9 Replies Latest reply on Apr 1, 2009 11:34 AM by Nicolas Gaudin

    SubView State Saving

    Nicolas Gaudin Newbie

      HI,

      One question:

      I am using

       <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>server</param-value>
       </context-param>
      


      I have a main (home) page with several includes. So globally, there are only ajaxRequests.

      How to get the actual viewId of the subview being refreshed or loaded?
      More how can I know that its state has already been saved in LRUMap, s o I can check its presence and avoid doing thing in PostConstruct of my JSF bean if this state is in session. (Indeed, I am dynamically positioning my components and would like to do it the first time a particular subview is loaded)


      I tried using the afterPhase of a customer phaseListener (phase id: RESTORE_VIEW) but I always get "/home.jsp" view Id. Meaning, UIViewRoot.getViewId() always returns "/home.jsp" even when rerendering an a4j:include.
      I also do not know how to acces the state of a particular subview in session.

      Hope someone can help me on this
      Or if anymone has another solution to check the state of a particular subview he is sincerely welcome
      Many thanks in advance




        • 1. Re: SubView State Saving
          Ilya Shaikovsky Master

          bind your a4j:inlucde's viewId's to backend beans and mange them in your actions/listeners.

          • 2. Re: SubView State Saving
            Nicolas Gaudin Newbie

            Thanks for your response

            My a4j:include's viewIds are bound to backend beans.

            You are meaning to add all visited subviews in a session map for instance..
            and then use @PostConstruct annotated method of by request scoped bean attached to each viewID (subview) to check if viewID present in the map.

            Do you confirm?

            For info, please:
            Is there a way to know that a particular subview viewId state is already in LRUmap (JSF stae saving mechnism) ?
            Could we use lifecycle RESTORE_VIEW phase to do it?

            • 3. Re: SubView State Saving
              Nick Belaevski Master

              Hello,

              UIViewRoot doesn't have any information about a4j:include, UIInclude components hold all information. Another way, as Ilya said, is creating binding of viewId to the model beans - you'll be able to implement any logic you like, basing on this model information.

              • 4. Re: SubView State Saving
                Nick Belaevski Master

                 

                "nicog" wrote:
                Is there a way to know that a particular subview viewId state is already in LRUmap (JSF stae saving mechnism) ?
                Better not do that: the solution won't be portable.

                • 5. Re: SubView State Saving
                  Nicolas Gaudin Newbie

                  Ok thanks

                  I managed to do it via binding and session bean list of view IDs...

                  My problem is that I am dynamically changing the parent of UI components as the position and hierachy (parent and children) of UI components is depending on database data that can be modified on the fly by users.

                  The problem:
                  I am first placing my components in jsp.
                  Based on database data, I might dynamically change the parent of a component using

                  oldparent.getChildren().remove(component);
                  newparent.getChildren().add(component);
                  


                  BUT my issue is that I have to set the moved component as TRANSIENT otherwise I get duplicate Id errors.

                  Doing so to avoid errors in save/restore view phase, when I do NOT reinitialise the component tree (as per Ilya solution and above discussion), the components are placed as in JSP.
                  That is normal as I put them as Transient and they are not saved in view. Kind of a vicious cycle here..

                  What can I do to solve this ?
                  Meaning NOT putting component as Transient AND NOT getting duplicate id errors?
                  If there is a solution, could it be implemented in @PostContruct annotated method of my request bean?

                  thanks in advance for your help
                  nico

                  • 6. Re: SubView State Saving
                    Nick Belaevski Master

                    Well, why not explore the reason you are getting duplicate id errors, while you shouldn't, to break this vicious cycle?

                    • 7. Re: SubView State Saving
                      Nicolas Gaudin Newbie


                      ok, first of all, i am fan of richfaces and sincerely think you are doing a damned great job.
                      But i need more help here as I am stuck.
                      i can assure that I spent hours and days investigating this.

                      => either duplicate Id or component tree with initial JSP tree structure

                      the thing is that moving a component from a parent to another generate this..
                      changes do not seem to be applied to the component tree.

                      do you think of any clue I could use?
                      I am doing the changes of the tree in @PostConstruct method of my bean..is that the issue?
                      If yes, how can I do otherwise?

                      Another thinking: would binding of all component in a keepalive bean would do what I am looking for?


                      • 8. Re: SubView State Saving
                        Nick Belaevski Master

                         

                        "nicog" wrote:
                        the thing is that moving a component from a parent to another generate this..
                        changes do not seem to be applied to the component tree.

                        Can you please prepare small demo project that will reproduce the issue?

                        "nicog" wrote:
                        Another thinking: would binding of all component in a keepalive bean would do what I am looking for?

                        Components should not be bound to KeepAlive beans.


                        • 9. Re: SubView State Saving
                          Nicolas Gaudin Newbie

                          I will try asap...
                          thks