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:

Tuesday, January 7, 2014

input type=“submit” Vs button tag are they interchangeable?

Buttons created with the BUTTON element function just like buttons created with the INPUT element, but they offer richer rendering possibilities: the BUTTON element may have content. For example, a BUTTON element that contains an image functions like and may resemble an INPUT element whose type is set to "image", but the BUTTON element type allows content.
So for functionnality only they're interchangeable!
(Don't forget you have to use type="submit" with button too.)