1 2 Previous Next 15 Replies Latest reply on Aug 29, 2007 9:15 PM by kevcpu411

    show/hide functionality

      I am having serious problems with the show/hide render functionality. Here is one example, I have a textbox whose visibility is determined by a value in a nearby radio button. I have tried this several different ways but I cannot get it to display, even after reRendering the outer container(h:panelGrid) which contains all of the components for this page. I dont understand why this does not work. I really need logic like this for this application as it could have security implications. Has anyone been able to find a reliable workaround for this problem? Show/Hide functionality is pretty important.

        • 1. Re: show/hide functionality

          show the code snippet, please.

          • 2. Re: show/hide functionality

            the scenario I mentioned earlier is one to be implemented. Here is the one I am currently dealing with. I have a delete button and I only want it to show after a new record has been entered in the database. I am using facelets + ajax4jsf. This code is in a separate page rendered inside a modalpanel using a4j:include. Forgot to mention that. The user will click "Add New" from a master page. A modalpanel will appear with empty textboxes where the user will enter their information. After the user clicks the save button the information will be saved to the database, the pnlStop will reRender and the delete will display at this point.

            Here is the code:

            <h:panelGroup id="pnlStop">
             <h:panelGrid columns="4" width="100%" height="100%" id="pnlTemplateManagePageItems"
             columnClasses="FirstColumn,SecondColumn,ThirdColumn,FourthColumn" >
             <f:facet name="header">
             <ks:kslabel id="txtHeader" value=" "></ks:kslabel>
             </f:facet>
             <ks:kslabel id="lblManageColumn4" value="Column 1"></ks:kslabel>
             <ks:kstextbox id="txtColumn4" binding="#{templateManage.txtColumn1}" required="false"></ks:kstextbox>
             <ks:kslabel id="lblManageColumn5" value="Column 2"></ks:kslabel>
             <ks:kstextbox id="txtColumn5" binding="#{templateManage.txtColumn2}" required="false"></ks:kstextbox>
             <ks:kslabel id="lblManageColumn6" value="Column 3"></ks:kslabel>
             <ks:kstextbox id="txtColumn6" binding="#{templateManage.txtColumn3}" required="false"></ks:kstextbox>
             <ks:kslabel id="lblManageColumn7" value=" "></ks:kslabel>
             <ks:kslabel id="lblManageColumn8" value=" "></ks:kslabel>
             <ks:kslabel id="lblManageColumn9" value=" "></ks:kslabel>
             <ks:kslabel id="lblManageColumn10" value=" "></ks:kslabel>
             <ks:kslabel id="lblManageColumn11" value=" "></ks:kslabel>
             <ks:kslabel id="lblManageColumn12" value=" "></ks:kslabel>
             <ks:kslabel id="lblManageColumn13" value=" "></ks:kslabel>
             <ks:kslabel id="lblManageColumn14" value=" "></ks:kslabel>
             <a4j:commandButton id="btnSave" value="Save" reRender="pnlStop" action="#{templateManage.save}">
             </a4j:commandButton>
             <a4j:commandButton id="btnDelete" value="Delete" action="#{templateManage.delete}"
             rendered="#{templateManage.hideDeleteButton}">
             </a4j:commandButton>
             </h:panelGrid>
             </h:panelGroup>
            


            • 3. Re: show/hide functionality

              Did not see what is wrong on the level of this page. (I see the next problem what you will face when this one will be solved).

              What action="#{templateManage.save} does? What it returns?

              • 4. Re: show/hide functionality

                At the moment it returns a string that is not mapped to any navigation rules. I did this so it would stay on this page until the user click the close link on the modalpanel. I still dont understand why the delete does not work if I am reRendering the outer container. The hideDeleteButton boolean is set after the save occurs and before the save action finishes. The error log does not contain any error messages either.

                • 5. Re: show/hide functionality

                  you want to stay on the same page (wizard page), it should return null.

                  Delete button should not work (that what I mentioned as 'next problem you will face'). To make it working, you should have the 'rendered' condition equals to true before the second jsf lifecycle phase. It is a core JSF behavior that has no relative to modal panel, ajax or what ever.

                  Does #{templateManage} have a request scope and you set hideDeleteButton only 'after the save occurs'?

                  • 6. Re: show/hide functionality

                    you want to stay on the same page (wizard page), it should return null.

                    Delete button should not work (that what I mentioned as 'next problem you will face'). To make it working, you should have the 'rendered' condition equals to true before the second jsf lifecycle phase. It is a core JSF behavior that has no relative to modal panel, ajax or what ever.

                    Does #{templateManage} have a request scope and you set hideDeleteButton only 'after the save occurs'?


                    How can I ensure the rendered condition equals to true before the second jsf lifecycle phase? I am using BackingBeans with ExadelStudio. The only exposure I really appear to have will be either from the action or in the constructor(BackingBean) unless I am missing something. How would you recommend I do this? Is there something I am missing?

                    • 7. Re: show/hide functionality

                      Does #{templateManage} have a request scope and you set hideDeleteButton only 'after the save occurs'?

                      The answer to your question is yes. The hideDeleteButton is updated within the save action.

                      • 8. Re: show/hide functionality

                        The easiest here, probably, is using a4j:keepAlive for the bean. So, the setting to true at the previous request will be visible on the second phase during the next request.

                        I.e. add <a4j:keepAlive beanName="templateManage" /> somewhere on the page.

                        Take a look at this wiki article http://tinyurl.com/2z2ckq . This is about similar case that you faced.

                        • 9. Re: show/hide functionality

                          the url you sent at http://tinyurl.com/2z2ckq does not work. Also, how resource intensive is the keepAlive?

                          • 10. Re: show/hide functionality

                            Hmm, it works for me. May be you have redirect of.

                            Let's try this way:
                            Click here

                            keepAlive serializes and stores the bean during the ajax requests from the same page. The bean is still a request scope bean. So, the value will be forgotten just after you leave the page where keepAlive is declared.

                            If you did not trust it, you have to figure our how to set the hideDeleteButton to true before the second phase is started.

                            • 11. Re: show/hide functionality

                              Also, how does the keepAlive affect the lifecycle. Is it the equivalent of a session bean or does it have a shorter cycle? The reason why I ask ... As a user selects records to edit I need a new data pull to occur each time to retrieve the currently selected record. Also, I have wizards that may utilize several beans and I might have problems with the keepAlive in this situation. I did this to keep the beans lightweight. Say I have a wizard that spans 7 different pages, it seemed resource intensive if I housed all of this in one bean as opposed to a separate bean for each wizard scenario. Can you think of a way that i can utilize the approach you discussed in the confines I outlined here? You mentioned there were other ways besides the easiest. What do you think would be the second easiest, third, etc.? :-)

                              • 12. Re: show/hide functionality

                                Hmm, it works for me. May be you have redirect of.

                                Let's try this way:
                                Click here

                                keepAlive serializes and stores the bean during the ajax requests from the same page. The bean is still a request scope bean. So, the value will be forgotten just after you leave the page where keepAlive is declared.

                                If you did not trust it, you have to figure our how to set the hideDeleteButton to true before the second phase is started.


                                The example I sent you worked for you? The button never shows up for me. Did you do it with or without the keepAlive?

                                • 13. Re: show/hide functionality

                                   

                                  "kevcpu411" wrote:

                                  The example I sent you worked for you? The button never shows up for me. Did you do it with or without the keepAlive?


                                  I spoke about the link to wiki, not about your code.

                                  • 14. Re: show/hide functionality

                                    oops, my bad.

                                    1 2 Previous Next