Conditional invocation of rich:popup panel

扶醉桌前 提交于 2019-12-14 03:19:52

问题


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.


回答1:


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>



回答2:


What I do is put the panel inside a panelGroup or some other container that can be rendered. Then set the rendered flag of that container depending on the condition and call render of that container when it possibly has to be shown.

something like this:

<a4j:commandButton ... render="popup"/>

<a4j:outputPanel id="popup" rendered="#{searchBackingBean.showLoginPanel}">
    <script>
        #{rich:component('loginPopup')}.show();
    </script>
</a4j:outputPanel>

MAG, Milo van der Zee



来源:https://stackoverflow.com/questions/8957560/conditional-invocation-of-richpopup-panel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!