9 Replies Latest reply on Oct 22, 2012 4:46 AM by facilus92

    How to display ModalPanel after some traitement in Java method

    facilus92

      Hello,

       

      I'm using a ModalPanel component to display popup on my page after clic in the save Button

       

      When i clic to the button, i do some traitement in Java "save" method, i retrieve some values as 'totalEntity'.

       

      I want to display ModalPanel before the methode ends and after retrieve my value 'totalEntity' on my save method.

       

      I dont want to display ModalPanel when i clic in save boutton directly.

       

      Thank's

        • 1. Re: How to display ModalPanel after some traitement in Java method
          sivaprasad9394

          Hi faycal,

           

          As per my understanding you like to do some back end operations(bean side) while clicking Save button in the screen.??

          Until it displays the result(totalEntry) after processing backend system you have to display the model panel.Is it like Processing model panel screen.???

          Mostly we can do with oncomplete and on click of the save button.

           

          Thanks,

          Siva

          • 2. Re: How to display ModalPanel after some traitement in Java method
            facilus92

            Yes,

             

            I want to do this with this condition :

             

            public void saveButton() {

             

            // traitement ....

            ....

             

            If (totalEntry.size() !=0 ) {

             

            // displaying modalPanel

             

            } else {

             

            // do not displaying modalPanel

             

            .....

            // end traitement

             

            }

            • 3. Re: How to display ModalPanel after some traitement in Java method
              sivaprasad9394

              Hi Faycal,

               

              In the if condition,you can declare String variable or boolean variable in the bean class and create getter and setter method.

              then set some value to the variable. like displayModel = true; OR displayModel = "Show";

               

              if(totalEntry.size()!=0)

              {

                   displayModel = "show";

                   OR

                    displayModel = true;

              }

              else

              {

               

              }

               

              -------------------------

               

              In jsp page or xhtml page,

               

               

              <rich:modalPanel id="imgPopUp" autosized="true" zindex="2000" width="650" rendered ="#{someBean.displayModel=="show"}"

                          OR rendered ="#{someBean.displayModel}">    

                          <f:facet name="header">

                              <h:panelGroup>

                                  <h:outputText value="Image"></h:outputText>

                              </h:panelGroup>

                          </f:facet>

                          <f:facet name="controls">

                              <h:panelGroup>

                                  <h:graphicImage value="/img/close.png"                      

                                      id="hidelinkimage" />

                                  <rich:componentControl for="imgPopUp" attachTo="hidelinkimage"

                                      operation="hide" event="onclick" />

                              </h:panelGroup> 

                          </f:facet>           

                          <h:panelGrid columns="2" border="0" width="650">   

                                   ----------------- UR CODE TO DISPLAY -----------------------------------

                          </h:panelGrid>       

                          

                   </rich:modalPanel> 

               

              So use rendered attribute for model panel or use showWhenRendered attribute for model panel. When clicking the Save button use reRender ="modelPanelID".

              While page loads it reloads rendered attribute and display it in the screen.

               

              Thanks,

              Siva

              • 4. Re: How to display ModalPanel after some traitement in Java method
                sivaprasad9394

                This will help you,

                 

                https://community.jboss.org/message/38987

                 

                Thanks,

                Siva

                • 5. Re: How to display ModalPanel after some traitement in Java method
                  facilus92

                  I try it with rendered but he dont work.

                   

                  I think i've mistake in my code , this is my code xhtml and java method :

                   

                  ------------------------- xhtml ---------------------------------------

                   

                  <div class="bt btSave">

                                                                              <a4j:commandLink action="save2" title="saved2" id="saveBtn" onclick="Richfaces.showModalPanel('popup');" reRender="popup">

                   

                                                                                      <span class="btleft"></span>

                                                                                        <span class="btmiddle">saved2</span>

                                                                                        <span class="btright"></span>

                                                                                        <span class="clear"></span>

                                                                              </a4j:commandLink>

                                                                    </div>

                   

                  <rich:modalPanel id="popup" rendere="#{entityController.showPopup}">

                                                          <f:facet name="header">

                                                                         <h:outputText value="Confirmation Clonage" />

                                                          </f:facet>

                                                          <f:facet name="controls">

                                                                         <h:outputLink value="#"

                                                                                        onclick="#{rich:component('popup')}.hide(); return false;">          X                                                       

                           </h:outputLink>

                                                          </f:facet>

                   

                   

                                                          <a4j:outputPanel id="compoPanelContents">

                   

                                                                              <p>This entity has more documents</p>

                   

                                                                              <p>

                        Nbre of documents to clone :

                                                                                        <h:outputText value="#{entityController.nbTransactionCloned}"

                                                                                                       styleClass="label" />

                                                                              </p>

                   

                                                                              <p>Want you really saved this entity and clone ?</p>

                   

                                                                              <a4j:commandLink value="Yes" action="clone"

                                                                                             oncomplete="if (#{facesContext.maximumSeverity==null})Richfaces.hideModalPanel('popup');" />

                                                                              <a4j:commandLink value="No" action="close"

                                                                                             oncomplete="if (#{facesContext.maximumSeverity==null})Richfaces.hideModalPanel('popup');" />

                   

                                                          </a4j:outputPanel>

                                                </rich:modalPanel>

                   

                  ----------------- Java Method -----------------

                   

                  public void saved2(Entity entity) {

                   

                  // doing some traitement for return specific list

                   

                                      this.nbTransactionCloned = list.size();  // for test, i've put constant value as '10'

                   

                  if (this.nbTransactionCloned != 0 ) {

                      setShowPopup(true);   // showPopup is an boolean attribut of Managed Bean (Controller)

                  } else {

                      setShowPopup(false);

                  }

                   

                  }

                   

                  -----------------------------

                   

                  When i clic , the ModalPanel was displaying without new value of 'nbTransactionCloned' and hidind automatiquelly quickly.

                   

                  I dont now where is mistake in code

                  • 6. Re: How to display ModalPanel after some traitement in Java method
                    facilus92

                    I dont no why the modalPanel is closed automatiquelly

                    • 7. Re: How to display ModalPanel after some traitement in Java method
                      mcmurdosound

                      there're some typos. For example:

                       

                      <rich:modalPanel id="popup" rendered="#{entityController.showPopup}">

                       

                       

                      and you should use oncomplete in this case:

                      <a4j:commandLink  title="saved2" id="saveBtn" oncomplete="Richfaces.showModalPanel('popup');" reRender="compoPanelContents"

                       

                      then you need an additional form in your modal panel because of the default attachment type: it will move the modalpanel to the body. therefore it wont be in the same form as declared. And you shouldn't declare modalpanels inside a h:form which include a form by itself!

                       

                      without corrent form-handling, the buttons / links which do ajax magic won't work.

                       

                      you should not rerender the modalpanel - try mpform:compoPanelContents if you h:form inside of the modalpanel but outside the compoPanelContents has the name /id "mpform"

                      • 8. Re: How to display ModalPanel after some traitement in Java method
                        facilus92

                        I've added the <h:form> in my ModalPanel and i used the 'oncomplete' , but the attribut reRender dont work always and my popup appears to the appearence of the page ... i dont know why !!!!!

                        • 9. Re: How to display ModalPanel after some traitement in Java method
                          facilus92

                          That's My code :

                           

                          ------------------------------------- xhtml of ModalPanel -----------------------------------------

                           

                          [code]

                           

                          <rich:modalPanel id="popup" autosized="true">

                                              <f:facet name="header">

                                                        <h:outputText value="Confirmation Clonage" />

                                              </f:facet>

                                              <f:facet name="controls">

                                                        <h:panelGroup>

                                                                  <h:graphicImage

                                                                            value="/stylesheet/img/Images/Gnome-Window-Close-32.png"

                                                                            styleClass="hidelink" id="hidelink" height="15" width="15" />

                                                                  <rich:componentControl for="popup" attachTo="hidelink"

                                                                            operation="hide" event="onclick" />

                                                        </h:panelGroup>

                                              </f:facet>

                           

                                              <a4j:outputPanel id="compo">

                                                        <a4j:form id="formPopup">

                                                                  <div class="clear"></div>

                                                                  <div class="clear"></div>

                           

                           

                                                                  <p>This entity has more documents</p>

                           

                           

                                                                  <p>

                                                                            Nbre of documents to clone :

                                                                            <h:outputText value="" styleClass="label" />

                                                                  </p>

                           

                                                                  <div style="margin-bottom: 30px" />

                           

                                                                  <h:panelGroup>

                           

                                                                            <a4j:commandLink reRender="identityForm, formPopup"

                                                                                                action="clone"

                                                                                                oncomplete="if (#{facesContext.maximumSeverity==null})Richfaces.hideModalPanel('popup');">

                                                                                      <span class="btleft"></span>

                                                                                      <span class="btmiddle">Save</span>

                                                                                      <span class="btright"></span>

                                                                                      <span class="clear"></span>

                                                                            </a4j:commandLink>

                           

                           

                                                                            <a4j:commandLink onclick="Richfaces.hideModalPanel('popup');"

                                                                                      action="close">

                                                                                      <span class="btleft"></span>

                                                                                      <span class="btmiddle">Cancel</span>

                                                                                      <span class="btright"></span>

                                                                                      <span class="clear"></span>

                                                                            </a4j:commandLink>

                           

                                                                  </h:panelGroup>

                                                        </a4j:form>

                                              </a4j:outputPanel>

                           

                                    </rich:modalPanel>

                           

                          [code]

                           

                           

                          ------------------------------------- xhtml of Button to show Popup-----------------------------------------

                          [code]

                           

                          <a4j:commandLink action="save" title="saved2" id="savedS" immediate="true"

                                                                                                          oncomplete="Richfaces.hideModalPanel('popup');" onclick="Richfaces.showModalPanel('popup');"

                                                                                                          reRender="formPopup">

                                                                                                <span class="btleft"></span>

                                                                                                <span class="btmiddle">saved2</span>

                                                                                                <span class="btright"></span>

                                                                                                <span class="clear"></span>

                                                                                      </a4j:commandLink>

                           

                          [code]

                           

                          Now, when i enter in the page, the popup was not showed (correct) but when i clic to the button "savedS" , the popup is display and hide automatiquelly !!!!

                           

                          I've added the attribut 'immediate' to keep it but, he dont work