开发者

Dynamically passing bean to rich:popupPanel

开发者 https://www.devze.com 2023-03-06 02:13 出处:网络
I have a base class, which is normal Java class. Three subclasses extend it which are @ViewScoped beans. There\'s a facelet using a dynamic variable. I have three xhtml pages which use this facelets w

I have a base class, which is normal Java class. Three subclasses extend it which are @ViewScoped beans. There's a facelet using a dynamic variable. I have three xhtml pages which use this facelets with the three beans viz. bean1, bean2 and bean3 which are dynamically included in a rich:tab component on a main page. So far so good. But on every page there are a few popups which should refer to the current bean. And since those popups need form tag inside them, I have included them 开发者_JAVA技巧outside the main page's form tags in order to avoid nested form tags. Now I want the popup to refer to current bean (bean1, bean2 or bean3, depending upon from where the popup is called) in question. How do I achieve this?


Try something like this:

  1. Add a new bean (popupBean) that will contain reference to current bean in popup.

  2. Add an action that will set needed bean as property of popupBean. Example:

    <h:commandLink>
        <a4j:ajax render="myPopup"/>
        <f:setPropertyActionListener target="#{popupBean.currentBean}" value="#{bean1}"/>
        <h:outputText value="Click ME!"/>
    </h:commandLink>
    
  3. Use show attribute of rich:popupPanel to show the popup:

    <rich:popupPanel id="myPopup" modal="true" width="600" moveable="true" 
            show="#{not empty popupBean.currentBean}" onmaskclick="#{rich:component('myPopup')}.hide();" autosized="true">
        <f:facet name="header"><h:outputText value="Cool popup!"/></f:facet>
        <h:panelGrid style="margin: 0">
            <h:panelGroup style="max-height: 400px;overflow-y: auto;" layout="block">
                <h:outputText value="#{popupBean.currentBean.myBeanProperty}"/>
            </h:panelGroup>
            <h:button value="Close" onclick="#{rich:component('myPopup')}.hide();return false;"/>
        </h:panelGrid>
    </rich:popupPanel>
    
0

精彩评论

暂无评论...
验证码 换一张
取 消