Friday, January 24, 2014

Conditionally displaying JSF components

Yes, use the rendered attribute.
 rendered="#{some boolean condition}">
where some boolean condition can be anything like:
 rendered="#{bean.booleanValue}" />
 rendered="#{bean.intValue gt 10}" />
 rendered="#{bean.objectValue eq null}" />
 rendered="#{bean.stringValue ne 'someValue'}" />
 rendered="#{not empty bean.collectionValue}" />
 rendered="#{not bean.booleanValue and bean.intValue ne 0}" />
 rendered="#{bean.enumValue eq 'ONE' or bean.enumValue eq 'TWO'}" />
Let's assume that the link is passing a parameter like
 href="page.xhtml?form=1">link
then you can show the form as follows
 rendered="#{param.form eq '1'}">
(the #{param} is an implicit EL object referring to a Map representing the request parameters)

See also:

No comments:

Post a Comment