8 Replies Latest reply on Mar 19, 2012 12:12 PM by jsf_pk

    Conditional onclick is not working in rich:popup

    jsf_pk

      Hi,

       

      I have a scenario where if my button enabled I have to call a bean method and redirect to another page and if button not enabled just hide the popup.

       

      Code below

        • 1. Re: Conditional onclick is not working in rich:popup
          jsf_pk

          <rich:popupPanel id="view_Req" model="true" autosized="true">

                              <f:facet name="header"><h:outputText value="Status Update"/> </f:facet>

                              <fieldset>

                              <legend><h:outputText value="Status"/></legend>

                              <center>

                              <a4j:outputPanel id="status_viewPanel">

                                  <h:form id="view_StatusForm">

                                          <h:selectOneRadio id="selectRadioValue" value="#{viewWageBean.requestStatus}">

                                              <f:selectItem id= "I"  itemValue="I" itemLabel="InComplete"/>

                                              <f:selectItem id= "C"  itemValue="C" itemLabel="Complete" />

                                              <f:selectItem id= "U"  itemValue="U" itemLabel="Unable to Complete"/>

                                            </h:selectOneRadio>

                                         

                                      <a4j:commandButton id="okButton" value="OK" action="#{viewWageBean.updateReqStatus}"/>

                                      <a4j:commandButton id="cancelButton" value="CANCEL" onclick="if (#{not viewWageBean.reaggDisabled}) updateName(); else #{rich:component('view_Req')}.hide();" />

                                     

                                  </h:form>

                              </a4j:outputPanel>

                              </center>

                              </fieldset>

                   </rich:popupPanel>

           

          <a4j:jsFunction name="updateName" action="#{viewWageBean.popupToSearchResult}"/>

           

          I am calling jsFunction to call the bean method to redirect to another page.

           

          Could anyone have idea how to acheive this?

          • 2. Re: Conditional onclick is not working in rich:popup
            sunkaram

            I don't see any problem with the code. Any issues in doing this?..

             

            You can also achieve the same result by

             

            <a4j:commandButton id="cancelButton1" value="CANCEL" onclick="#{rich:component('view_Req')}.hide();" rendered="#{viewWageBean.reaggDisabled}"/>

            <a4j:commandButton id="cancelButton2" value="CANCEL" action="#{viewWageBean.popupToSearchResult}" rendered="#{ ! viewWageBean.reaggDisabled}"/>

            • 3. Re: Conditional onclick is not working in rich:popup
              jsf_pk

              Only once it is working. After then, Only hide is called not the action.

              • 4. Re: Conditional onclick is not working in rich:popup
                sunkaram

                Check if you are rerendering the elements in the popup panel each time you change 'reaggDisabled' flag.

                show(), hide() will not rerender the popup elements.

                • 5. Re: Conditional onclick is not working in rich:popup
                  jsf_pk

                  Hi Mahes,

                   

                  Sorry for the very late reply. I was outstationed.

                   

                  Yes you're correct. The 2nd option (id = cancelButton2) is not rendering the button. I am calling this popup from another popup based on the condition.

                  <a4j:commandButton id="reagg_btn" value="Re-Aggregate" actionListener="#{viewWageBean.calReaggregate}" disabled="#{viewWageBean.reaggDisabled}" render="tapPanel,wageBtns,Message_info">   </a4j:commandButton>

                  <a4j:commandButton id="close_btn" value="Close"
                        onclick="if (#{!viewWageBean.reaggDisabled}) #{rich:component('save_exclusion')}.show(); else #{rich:component('view_Req')}.show();" />

                   

                  When I click on the Close button, if the Re-Aggregate button is enabled, then I called the save_exclusion popup. In that PopUp, if user choose 'NO', then I call another popup View_Req. Here is the actual problem...

                   

                  <rich:popupPanel id="save_exclusion" model="true" autosized="true">
                                <f:facet name="header"><h:outputText value="Save Exclusions"/> </f:facet>
                                <center>
                                <a4j:outputPanel id="save_viewPanel">
                                 <h:form id="save_ViewStatusForm">
                                  <p>
                                   You have made Exclusions, and need to Re-Aggregate.<br/>
                                   If you wish to close the screen and not Re-Aggregate <br/>
                                   Press 'NO' otherwise Press 'YES' and perform Re-Aggregation.
                                  </p>
                         <a4j:commandButton id="okButton" value="YES" onclick="#{rich:component('save_exclusion')}.hide();"/>
                         <a4j:commandButton id="cancelButton" value="NO" onclick="#{rich:component('view_Req')}.show();"  oncomplete="#{rich:component('save_exclusion')}.hide();"/>
                        </h:form>
                       </a4j:outputPanel>
                       </center>
                        </rich:popupPanel>
                    

                  But the state is not passing here? Any idea how to resolve this?

                  • 6. Re: Conditional onclick is not working in rich:popup
                    sunkaram

                    try re-rendering 'okButton', 'cancelButton' when user clicks on 'Close' button

                     

                    <a4j:commandButton id="close_btn" value="Close" render="okButton,cancelButton"

                          onclick="if (#{!viewWageBean.reaggDisabled}) #{rich:component('save_exclusion')}.show(); else #{rich:component('view_Req')}.show();" />

                    • 7. Re: Conditional onclick is not working in rich:popup
                      sunkaram

                      adding ajaxRendered="true" for <a4j:outputPanel id="save_viewPanel" ajaxRendered="true"> should work too..

                      • 8. Re: Conditional onclick is not working in rich:popup
                        jsf_pk

                        Thanks Mahes,

                         

                        It is working now. Those rendered attributes are working after you suggest to put the ajaxRendered="true". I can do cancel in one scenario and redirect to another page in another scenario.