5 Replies Latest reply on Feb 23, 2012 9:40 AM by jsf_pk

    Generate Pop Up from Server Side using JSF/Richfaces

    jsf_pk

      Hi,

       

      I have a requirement, when user doesn't meet certain criteria, I have to show pop ups (generate from server side)

      1) OK and Cancel button.

       

      When user click on OK, he has to go to another page.

      When user click on Cancel, he has to stay on the source page.

       

      How do I acheive this in using JSF2.0/Richfaces 4.0

        • 1. Re: Generate Pop Up from Server Side using JSF/Richfaces
          iabughosh

          hello parthi,

          try this psudo code:

           

          <h:form>

               <a4j:commandButton id="submit"

                                               value="submit"

                                               actionListener="#{yourBean.validateYourCriteria}"

                                               oncomplete="if(#{yourBean.isValid}){#{rich:component('yourPopup')}.show();}"/>

           

               <rich:popupPanel id="yourPopup" domElementAttachment="form">

                    <h:commandButton id="ok" value="ok" action="#{yourBean.navigateToAnotherPage}"/>

                    <h:commandButton id="cancel" onclick="#{rich:component('yourPopup')}.hide(); return false;"/>

               </rich:popupPanel>

          </h:form>

           

          regards.

          • 2. Re: Generate Pop Up from Server Side using JSF/Richfaces
            jsf_pk

            Thanks Ibrahim,

             

            This is working.

             

            But is there any way to generate the pop up from server side?

             

            the below sceneria

             

            SearchResultActionBean.java

            if(StringUtils.equals(search.getRequestStatus(), UpswcsConstants.AGGREGATION_FAILURE)){

                                message = " Aggregation: Failed" +

                                             " The aggregation process for this request has failed. "+

                                             " Please contact the help desk quoting the " +

                                             " Social Security number and Reply Date. " +

                                             " Would you likt to view Payroll Details. ";

             

            When this condition satisfied, I have to set this message in the pop up added with OK and Cancel button? How can I acheive this?

            • 3. Re: Generate Pop Up from Server Side using JSF/Richfaces
              iabughosh

              ok, there is no much changes to the previous code,

               

              add to your bean String msg; with getters and setters then modify your action listener(actionListener="#{yourBean.validateYourCriteria}") method:

              to set your msg like your post.

               

              in your xhtml page add render attribute to your submit button:

               

              <h:form>

                   <a4j:commandButton id="submit"

                                                   value="submit"

                                                   render="yourPopup"

                                                   actionListener="#{yourBean.validateYourCriteria}"

                                                   oncomplete="if(#{yourBean.isValid}){#{rich:component('yourPopup')}.show();}"/>

               

                   <rich:popupPanel id="yourPopup" domElementAttachment="form">

                        <div align="center">

                             <h:outputText value="#{yourBean.msg}"/><br/>

                             <h:commandButton id="ok" value="ok" action="#{yourBean.navigateToAnotherPage}"/>

                             <h:commandButton id="cancel" onclick="#{rich:component('yourPopup')}.hide(); return false;"/>

                        </div>

                   </rich:popupPanel>

              </h:form>

              • 4. Re: Generate Pop Up from Server Side using JSF/Richfaces
                healeyb

                Have a look at the rich:popupPanel show= attribute - this is supposed to be for displaying a popupPanel from a server

                side action, although I've not tried it myself. An associated comment in "Pratical Richfaces 2" says that if you're making

                changes via ajax "don't forget to update the entire component in order for it to get re-initialized and shown/hidden based

                on a new value". I take this to mean use the id of the popopPanel itself, not the content as you'd normally do.

                 

                Regards,

                Brendan.

                • 5. Re: Generate Pop Up from Server Side using JSF/Richfaces
                  jsf_pk

                  Hi,

                   

                  Sorry for the late reply...I got bugged in another problem I cant see your reply...

                   

                  Very thanks for the reply's.

                   

                  Do you havea  any code samples available with you for how to call the popup from java code?