7 Replies Latest reply on Aug 5, 2009 3:59 AM by Ilya Shaikovsky

    State management problem

    Pieter Porre Newbie

      Not sure where to put this question...

      We are developing an application which is using dynamically created tabs that include dynamic pages.

      Our beans are kept alive with <a4j:keepAlive> so that they are kept in the ajax session. (configured with scope request).
      The problem is when we close a tab where we have worked in and reopen that same page in a new tab. This view is restored and the last entered data is still visible in this page.

      Is there a way to clean the beans after we close the tab without doing it ourselves with a clean method in the beans? (remove them from state / ajax session or somethin?).

      And is there a way that we can have multiple instances of these beans so that the 'same' page can be opened multiple times without interfering with each other?

      Thx in advance.

        • 2. Re: State management problem
          Pieter Porre Newbie

          This is the code where I use my tabs.

          <rich:tabPanel id="tabs" switchType="client" >
           <c:forEach var="i" begin="0" end="#{navigationBean.numberOfTabs}" step="1" varStatus="status">
           <rich:tab name="tab#{status.index}">
           <f:facet name="label">
           <h:panelGrid columns="2">
           <h:outputText value="#{navigationBean.tabs[status.index].label}" />
           <h:graphicImage value="/images/closeicon.gif"
           style="width:12px; height:12px;"
           onclick="closeTab('#{status.index}'); Event.stop(event);"/>
           </h:panelGrid>
           </f:facet>
           <a4j:include keepTransient="false" viewId="#{navigationBean.tabs[status.index].path}" layout="block" />
           </rich:tab>
           </c:forEach>
          </rich:tabPanel>
          


          The navigationBean holds an array of Objects where the path to inlcude and the label is stored.

          This is the code where I remove my 'tab'. When this is done the tabPanel is rerendered.

          public void removeTab() {
           this.tabs.remove(activeTabIndex);
           numberOfTabs--;
           if (activeTabIndex == 0) {
           makeActiveTab(0);
           } else {
           makeActiveTab(activeTabIndex - 1);
           }
           nextTabIndex--;
           }
          


          If you need more information please ask me. I really could use the help.

          Thx

          • 3. Re: State management problem
            Pieter Porre Newbie

            And sorry about the misplacement of the other post.

            Don't know how I could have missed the topic on posting.

            • 4. Re: State management problem
              Alexander Smirnov Master

              What is your navigation bean scope ?
              The keepAlive component suppose to work with request-scope bean. JSF framework instantiates that bean on the first request and that instance stored in the view tree. For subsequent request bean instance will be restored from view and takes place of the bean.
              Because JSF does not restore view state for non-post request, you will have a new navigationBean instance for request from a new tab ( even simple 'refresh' page request should reset that bean.
              a4j:keepAlive component has a very limited functionality. For a more powerful solution, take look on Jboss Seam framework and its 'conversation' scope.

              • 5. Re: State management problem
                Pieter Porre Newbie

                Thx for you reply.

                My NavigationBean is session scoped. Because the count and such for my tabs must be kept.

                My keepAlive is put on the pages that are loaded in the a4j:include.

                My problem lays in the fact that I need a way to clean the beans for my included pages when I close a tab.

                I know what pages / beans are loaded in a tab so that is not a problem. I just can't get them out of the view tree.

                I have looked at seam and I believe this could be an option but I may not use it in this project. (stupid/ignorant project managers) ;-)

                • 6. Re: State management problem
                  Pieter Porre Newbie

                  I have not yet found a solution for this problem so any help would be greatly appreciated.

                  Thx

                  • 7. Re: State management problem
                    Ilya Shaikovsky Master

                    In one of the Max articles http://java.dzone.com/articles/jboss-richfaces-spring?page=0,5 reseting kept alive bean defined well as

                    FacesContext.getCurrentInstance().getExternalContext().getRequestMap()
                    .remove("wizardBean");