5 Replies Latest reply on Feb 24, 2012 12:28 PM by trigun

    popupPanel calling Bean

    trigun

      Hi all,

       

      I have the following setup on my Page:

       

      popupPanels.xhtml which includes the following popups:

       

      <h:panelGroup id="popupPanels" layout="block" style="display: none;">

                          <ui:include src="/misc/registerPopup.xhtml" />

                          <ui:include src="/misc/statusPopup.xhtml" />

                          <ui:include src="/misc/createAlbumPopup.xhtml"/>

      </h:panelGroup>

       

      then in the template.xhtml of my Page i unclude all Popups by <ui:include src="/misc/popupPanels.xhtml"/> so they are allways available.

      Now i have a problem with registerPopup:

       

      <rich:popupPanel id="registerPopup" width="500" height="600" resizeable="false"

                                    autosized="true" onshow="#{rich:element('usernameReg')}.focus()">

       

                                                        <h:form id="registerForm">

                                                        <rich:graphValidator id="regVal">

                                                        <rich:panel id="createUserPanel" >

       

                                                                            <h2 style="color:#0E385F;">#{msgBv['createBenutzer.titel']}</h2>

                                                                            <p/>

                                                                            <h:panelGrid id="regGrid" columns="2"  >

                                                                                <h:outputLabel for="usernameReg" value="#{msgBv['createBenutzer.benutzername']}"/>

                                                                                      <h:inputText id="usernameReg" value="#{reg.newUser.username}">

                                                                                                <a4j:ajax event="change" listener="#{reg.usernameExists}" render="createUserPanel"/>

                                                                                      </h:inputText>

       

                                                                                      <h:outputLabel for="nachname" value="#{msgBv['createBenutzer.nachname']}"/>

                                                                                      <h:inputText id="nachname" value="#{reg.newUser.nachname}" styleClass="inputtext" />

      ....................

      ....................

       

      reg.newUser.username points to a @ConversationScoped Bean. The problem now is that my Bean gets initialized on Page load alltough i don`t call the Popup to show ?!

      I want to show the popup on click of the register button and init the conversation there:

       

      <a4j:commandButton value="#{msgBv['benutzer.register']}" rendered="#{not auth.loggedIn}"

                                                                  actionListener="#{reg.init}" oncomplete="#{rich:component('registerPopup')}.show(); "

                                                                  render="createUserPanel"/>

       

      How can i prevent the Rigister bean to be loaded until i show the register popup ?

       

      Thank you

        • 1. Re: popupPanel calling Bean
          iabughosh

          Hello trigun,

          rich:popupPanels are rendered when page is loaded but they are hidden, so it is normal behavior to see your beens getting initialized, if you want your beans to get initialized only when your popup is called,

          i think you have to play a bit with rendered attribute to render/de-render your popup when you show/hide it .

           

          regards.

          • 2. Re: popupPanel calling Bean
            sunkaram

            try this

             

            change popupPanels.xhtml to

            <h:panelGroup id="popupPanels" layout="block" style="display: none;">

                                <ui:include src="/misc/registerPopup.xhtml" />

                                <h:panelGroup id="regPopUpId">

                                     <ui:include src="/misc/statusPopup.xhtml" />

                                </h:panelGroup>

                                <ui:include src="/misc/createAlbumPopup.xhtml"/>

            </h:panelGroup>

             

            In registerPopup

             

            add

            <a4j:jsFunction name="renderRegPopUp"  render="regPopUpId"/>

             

            and change <a4j:commandButton to

            <a4j:commandButton value="#{msgBv['benutzer.register']}" rendered="#{not auth.loggedIn}"

                                                                        actionListener="#{reg.init}" oncomplete="renderRegPopUp();#{rich:component('registerPopup')}.show(); "

                                                                        render="createUserPanel"/>

            • 3. Re: popupPanel calling Bean
              trigun

              Thank you Maheswara,

               

              i tryed your solution but got the following error:

               

              Uncaught TypeError: Cannot call method 'show' of undefined

               

              my popupPanels.xhtml looks like this:

               

              <h:panelGroup id="popupPanels" layout="block" style="display: none;">

                                  <h:panelGroup id="regPopUpId" rendered="false">

                                            <ui:include src="/misc/registerPopup.xhtml" />

                                  </h:panelGroup>

                                  <ui:include src="/misc/statusPopup.xhtml" />

                                  <ui:include src="/misc/createAlbumPopup.xhtml"/>

              </h:panelGroup>

               

              in your example you don`t have rendered="false" to regPupUpId ?! i think you ment it like this ?

              The good thing on this is, my conversation bean didn`t get called.

               

              I think the problem now is that when the jsFunction:

                   <a4j:jsFunction name="renderRegPopUp"  render="regPopUpId" onbegin="console.log('test')"/>

              is called the regPopUpId isn`t rendered already ?

               

              Any suggestion ?

               

              Thanks for your help


              • 4. Re: popupPanel calling Bean
                sunkaram

                if we keep rendered=false for panelGroup, this id won't be available to render later. That is the reason for that error. so try like this 

                 

                maintain a boolean property regPopUpDisplay in bean and make it 'false' by default. (not sure if <ui:include has rendered property..)

                 

                <h:panelGroup id="regPopUpId">

                     <h:panelGroup  rendered="#{bean.regPopUpDisplay}">

                          <ui:include src="/misc/registerPopup.xhtml" />

                     </h:panelGroup>    

                </h:panelGroup>

                 

                When user clicks on <a4j:commandButton

                 

                change the regPopUpDisplay to 'true'.

                • 5. Re: popupPanel calling Bean
                  trigun

                  I tryed this solutuin before, but then i can`t us my conversationscoped bean to hold the state for regPopupDisplay because then it get`s instantiated on every page load, or am i wrong ?

                   

                  I can use my Authenticator which is sessiocscoped for this, but i don`t wanna have this in Authenticator because it not belongs to this bean. I thnik this is not a "clean" solution then...

                   

                  Thanks