1 2 Previous Next 26 Replies Latest reply on Mar 19, 2009 10:03 AM by nbelaevski Go to original post
      • 15. Re: Bean executed twice - while calling and exiting the web

         

        "nbelaevski" wrote:
        Enclose components that generate requests (e.g. that have "action" attribute in reference guide/tld) into a4j:region components. Data tables should not be included into regions. Check livedemo for "region" component to see how this works.


        Do you mean, that all data tables should not be included into regions?

        • 16. Re: Bean executed twice - while calling and exiting the web

          Perhaps the reason is that, you have a4j component in the first page, when switch to page2, the a4j component must be restored or??? The setter and getter method will be called again.

          • 17. Re: Bean executed twice - while calling and exiting the web
            aish

            Hi,

            I tried using a4j:region in the following way.

            <rich:dropDownMenu value="Section A">
            <a4j:region>
            <rich:menuItem value="System A" action="#{navigate.doSystemA}" id="dropdownmenu_mItem1" />
            </a4j:region>
            <a4j:region>
            <rich:menuItem value="System B" action="#{navigate.doSystemB}" id="dropdownmenu_mItem2" />
            </a4j:region>
            </rich:dropDownMenu>


            But what happened was - It blocked themenu item from getting displayed.

            I believe I did wrong in including the a4j:region. Please correct me

            Also, Should I include a4j:region for both panelmenu item and drop down menu item?
            Thanks
            Aish

            • 18. Re: Bean executed twice - while calling and exiting the web
              ilya_shaikovsky

              Lets start from scratch.

              As I already told you there is nothing specific to ajax or something else. Lets not to try doing magic but check the reasons.

              B.t.w. sorry about wrong immediate suggestion. It was my fault.

              So

              If you just take a h:dataTable(standard one) and h:commandButton(the same) you will see the result you describing. It's just because the table gets its model on decodes. Using regions is a good way during partial page updates and it should do the work, but also not applicable in your case because you performing navigation which should be performed with the server mode of the menu(so the submit becomes just as with standard h:command* ). And immediate also isn't a solutions.

              So some set of general advices.

              1) taking the data from db in table getters isn't good idea at all. The table model getting called few times during submit within the page(page decode, page rendering..) just by JSF framework. So you should use the session bean for example which populated from db and then used with the populated data without db calls.
              2) in your case you also could separate the form to two ones. One for the menu and the second for the dataTable. In this case table processing will not be invoked at all.
              3) As Nick suggested you could write the phaseListener in order to switch rendering of the table to false. But it seems for me that this will be just workaround and should not be used if you trying to achieve good application design in general.

              • 19. Re: Bean executed twice - while calling and exiting the web
                aish

                Hi Ilya,

                Thank you for your input and your support as always. I thought I can clarify with you the following before I try.

                Based on your suggestions:

                1) taking the data from db in table getters isn't good idea at all. The table model getting called few times during submit within the page(page decode, page rendering..) just by JSF framework. So you should use the session bean for example which populated from db and then used with the populated data without db calls.

                ==== I should be using something like getDataTableListA as given below instead of getDataTableListB?

                Should be using this:
                ------------------------
                public List getDataTableListA() {
                if (dataList == null) {
                loadDataList(); }
                return dataList;
                }

                Instead of
                -----------

                public List getDataTableListB()
                {
                a. connect to datatable
                b. Get ResultSet
                c. Loop thru ResultSet
                return dataList;
                }

                2) in your case you also could separate the form to two ones. One for the menu and the second for the dataTable. In this case table processing will not be invoked at all.

                ===== I wonder this would involve 2 forms nested within each other which is not allowed. Please look at my index.jsp that I have enclosed earlier. I will give it a try and let you know how that goes.

                Thanks a lot
                Aish


                • 20. Re: Bean executed twice - while calling and exiting the web
                  ilya_shaikovsky

                  1) yes something like this.
                  2) i do not meant nested forms. but the construction like form.. menu.. /form..form.. table.. /form

                  • 21. Re: Bean executed twice - while calling and exiting the web
                    nbelaevski

                    1. You can use request-scoped beans.

                    • 22. Re: Bean executed twice - while calling and exiting the web
                      aish

                      Hi Ilya,nbelaevski,

                      Thanks for getting back to me.

                      Regarding the two options Ilya had suggested, I tried the second option of having one form for menu and one form for dataTable. It worked fine. The bean was not called twice. Thanks a lot for your help.

                      I will also implement the second option and let you know how it goes. One thing, I have is - I extract a subset of rows from the database and not all at the sametime. By selection of "next set of rows" by the user, I go back to the database to get the next set of rows. I need to see how it would work out

                      Thanks
                      Aish

                      • 23. Re: Bean executed twice - while calling and exiting the web
                        aish

                        Hi Ilya,nbelaevski,

                        In continuation with my earlier post, I also would like to check this. When I select a row in a scrollableDataTable using a commandButton, it submits the form and the entire bean is executed from the beginning instead of calling just the action method related to the commandButton. Here is how I have the commandButton. The commandButton is hidden and hence when the user selects the row, the javascript ClickButton is called and submits the command button

                        <a4j:commandButton id="Button1" value="."
                        action="#{process.extractDetails}" reRender="Panel1"/>


                        <a4j:outputPanel id="Panel1">

                        <rich:scrollableDataTable rowKeyVar="rkv" height="400px" first="0"
                        width="720px" id="sTable" value="#{process.Details}" var="Tbl"
                        sortMode="single" selection="#{process.dtSelection}"
                        binding="#{process.Table}"
                        focus="sTable" onRowClick="ClickButton()" >

                        <columns......>


                        </a4j:outputPanel>

                        I once tried the immediate="true" option and that didnt help either. It executed the entire bean.

                        Please let me know why the bean is executed from the start when the command button is selected and how to prevent it?

                        Thanks a lot
                        Aish

                        • 24. Re: Bean executed twice - while calling and exiting the web
                          nbelaevski

                           

                          entire bean is executed


                          Please clarify, what do you mean by executed: bean is instantiated, some method is called? Which bean and/or which method?

                          • 25. Re: Bean executed twice - while calling and exiting the web
                            aish

                            Hi,

                            Let me clarify what I had mentioned earlier about "the bean is executed from the start". The bean is instantiated once again as if I was called the first time.

                            Please let me know if that helps to answer my earlier post

                            Thanks
                            Aish

                            • 26. Re: Bean executed twice - while calling and exiting the web
                              nbelaevski

                              Aish,

                              Sure, it must be instantiated:

                              binding="#{process.Table}"
                              .

                              1 2 Previous Next