Search code examples
jsf-2richfaces

Conditional invocation of rich:popup panel


Hello Everyone I would like to open a rich:popupPanel inside a conditional expression, actually what I'm trying is something like this:

onclick="#{searchBackingBean.showLoginPanel==true ? #{rich:component('loginPopup')}.show();':''}"

However I'm getting errors related to EL, how should I write this correctly?. Thanks a lot.


Solution

  • You may not nest EL expressions. I suggest to rewrite the expression as follows so that the condition is delegated to JavaScript:

    onclick="if (#{searchBackingBean.showLoginPanel}) #{rich:component('loginPopup')}.show();"
    

    (please note that I removed the superfluous == true comparison because this makes no sense as the method returns/prints a boolean value already)

    Note that this only works in <rich:xxx> and <a4j:xxx> components as they have enhanced the on* attributes to re-evaluate the EL expression on postbacks. The standard JSF <h:xxx> components doesn't do that. You'd need to workaround it with the rendered attribute:

    <h:commandButton>
        <f:ajax render="script" />
    </h:commandButton>
    <h:panelGroup id="script">
        <h:panelGroup rendered="#{searchBackingBean.showLoginPanel}">
            <script>#{rich:component('loginPopup')}.show();</script>
        </h:panelGroup>
    </h:panelGroup>