Saturday, February 9, 2013

rendered attribute in Primefaces

There is a known issue with the rendered attribute in Primefaces -- the element can't be updated if it doesn't exist in DOM. 
Thus, there could be problem to render it with ajax. 
eg,
<h:panelGroup id="pg" rendered="#{testBean.flag}">
    <h:outputLabel value="this is a panel group" />
</h:panelGroup>

above sample can't be render with ajax.

There are 2 workarounds to resolve the above situation.

option 1: wrap a outer panel group, and render the outer panel group with ajax.
eg, render the outerPG with ajax instead of pg.
<h:panelGroup id="outerPG">
    <h:panelGroup id="pg" rendered="#{testBean.flag}">
        <h:outputLabel value="this is a panel group" />
    </h:panelGroup>
</h:panelGroup>
option 2: declare the rendered condition with <c:if />
eg,
<h:panelGroup id="pg">
    <c:if test="#{testBean.flag}">
        <h:outputLabel value="this is a panel group" />
    </c:if>
</h:panelGroup>nnn

option 2 would be better alternative, because option 2 can even reduce the JSF component tree size. 
Because all JSF components within <c:if /> will be removed from the component tree when the <c:if /> test result is false. 

Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...