Friday, June 22, 2012

rendered attribute in jsf

JSF has a very nice support for ajax. You can specify ajax behavior using f:ajax tag with any input or command components.  However, rendered attribute gives you surprise sometime.
Suppose you have a component in xhtml like this
<h:datatable ... rendered="#{empty configs}">
In you ajax tag, you'd like to refer to this table in render attribute.  Since your table could never be rendered, and not in the component tree, client code and server code will not be able to update it in ajax call.  You could use OutputPanel from richfaces library. However, there is a much simple soltuion: render your component in all time. Replace the rendered="false" case with something like style="display:none".

<h:datatable ... styleClass="#{(empty configs)?'displayhidden':'displaytable'}">

No comments:

Post a Comment