2011-06-22 15 views
4

JSTLタグを使用せずにJSFで条件付きロジックを実行できますか?JSFの条件付き

たとえば、複合コンポーネントを作成し、 'id'属性が指定されている場合は 'id'属性を定義しますが、 'id'属性が指定されていない場合は指定しません'id'属性。

私はレンダリングされた属性を使用しなければなりませんが、idを指定するかどうかにわずかな違いがあります。

<composite:interface> 
    <composite:attribute name="id" /> 
     ... 
</composite:interface> 

<composite:implementation> 
    <!-- render this when id is specified, id attribute is defined --> 
    <h:selectOneMenu 
       id="#{cc.attrs.id}" 
       label="#{cc.attrs.label}" 
       value="#{cc.attrs.value}" 
       rendered="#{cc.attrs.id != null}" ...> 
       ... 
    </h:selectOneMenu> 

    <!-- render this when id is not specified, id attribute is NOT defined --> 
    <h:selectOneMenu 
       label="#{cc.attrs.label}" 
       value="#{cc.attrs.value}" 
       rendered="#{cc.attrs.id == null}" ...> 
       ... 
    </h:selectOneMenu> 
</composite:implementation> 

この複製を避け、条件付きのものをより簡単に行うためのアイデアはありますか?

ありがとうございました!

答えて

2

ご自身でidをご指定ください。

<h:selectOneMenu 
    id="#{not empty cc.attrs.id ? cc.attrs.id : 'menu'}" 
    label="#{cc.attrs.label}" 
    value="#{cc.attrs.value}"> 
    ... 
</h:selectOneMenu> 

componentssiteコンポーネントの独自のクライアントIDが先頭に追加されるため、いずれにしても一意になります。