Conditionally in JSF

Is it possible to make conditional logic with JSF without JSTL tags?

For example, I created a composite component and want to indicate if the id attribute is specified, then define the id attribute, but if the id attribute is not specified, then do not specify 'id'.

At the moment I should use the rendered attribute, but there are so many duplicates there, with a slight difference in the id indication or not.

<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> 

Any ideas to avoid this duplication and make conditional material easier?

Thanks!

+4
source share
1 answer

Set the default id yourself.

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

It will be unique, as it will add its own client identifier for the component.

+2
source

All Articles