3 Replies Latest reply on Nov 8, 2007 4:34 PM by tim_ph

    Switching instance of backing bean of JSF page with Seam

    tim_ph

      I got this scenario that requires to switch view page to new copied of old backing instance.
      - A JSF page of current instance object is used to modify the object.
      - The action results in a new clone of object is created with modified data.
      - Both objects are persisted.
      - I want to show the JSF view page of the new clone, not existing instance.

      The problem is with s:button, s:link view of next page need the id of instance object, but the id is not known until object is persisted. If you map <f:param name="id" value="#{objHome.objId}"/>, you got the current id populated that value when the page is loaded.

      What option do I have for this situation?

        • 1. Re: Switching instance of backing bean of JSF page with Seam
          damianharvey

          Have you tried outjecting both copies into the Conversation context and then just referencing them in the Bean backing the next page?
          eg:

          @Out(ScopeType.CONVERSATION)
          Bean oldBean;
          
          @Out(ScopeType.CONVERSATION)
          Bean newBean;

          Cheers,

          Damian.


          • 2. Re: Switching instance of backing bean of JSF page with Seam
            tim_ph

            Well, I use one page with backing bean in Seam Framework.
            - page.xml set id, which backing object Home use to load up the instance from DB
            - page.xhtml get loaded with instance populated
            - one page for view, one for edit
            I try to switch old bean with new one as in objHome.setInstance() and setId(), but that won't work because when you set the view page on s:button with no id, it just uses current id for the next page. So, when the page is loaded, old instance populates the page.

            Just thinking about using navigation from-action in page.xml like this

             <navigation from-action="#{applicationHome.manager.action}">
             <rule if-outcome="success">
             <redirect view-id="Application.xhtml">
             <param name="applicationId" value="#{applicationHome.instance.id}"/>
             </redirect>
             </rule>
             </navigation>
            
            
            If redirect populate #{applicationHome.instance.id} after action is done, then it will work. If not, current id will populate that, and we're back to square one.
            Let me give it a try.
            
            


            • 3. Re: Switching instance of backing bean of JSF page with Seam
              tim_ph

              It's very sticky.

              After setting id to new object and return "success" from method action, the URL is showing applicationId = new application ID, but the instance on the page is still the same old one! Arghhh...


               Long id = newclone.getId();
               applicationHome.setId(id);
               applicationHome.setInstance(newclone);
               return "success";