8 Replies Latest reply on Dec 24, 2007 7:22 AM by pmuir

    Why PAGE context variable = NULL

    damnh

      Why variable mode = NULL when inject, outject to PAGE scope:

      @Stateful
      @Name("listAction")
      @Scope(SESSION)
      @Restrict("#{identity.loggedIn}")
      public class ListAction implements
       IListAction {
      .........
       @In(required = false)
       @Out(required = false, scope = ScopeType.PAGE)
       private String mode;
      ..........
      }
      

      @Stateful
      @Name("regAction")
      @Restrict("#{identity.loggedIn}")
      public class RegAction implements IRegAction {
      
       ...........
       @In(required = false)
       @Out(required = false, scope = ScopeType.PAGE)
       private String mode;
      ..........
      }
      

      This is my pages.xml
      <page view-id="/list.xhtml" login-required="true">
       <navigation from-action="#{regAction.init}">
       <begin-conversation flush-mode="manual" />
       <redirect view-id="/register.xhtml" />
       </navigation>
      </page>
      


      If I use render intstead of redirect, variable mode != NULL. Is this Seam's bug?

      Please show me cause of this problem, thanks.

        • 1. Re: Why PAGE context variable = NULL
          damnh

          what is this problem? Please help me

          • 2. Re: Why PAGE context variable = NULL
            pmuir

            Post, clearly, the execution flow of your app involving these variables/components.

            • 3. Re: Why PAGE context variable = NULL
              damnh

              I want to pass variable mode (or variable with type Object) from /list.xhtml page to /register.xhtml page, I used PAGE scope to pass.

              @Stateful
              @Name("listAction")
              @Scope(SESSION)
              @Restrict("#{identity.loggedIn}")
              public class ListAction implements
               IListAction {
              .........
               @In(required = false)
               @Out(required = false, scope = ScopeType.PAGE)
               private String mode;
              
               public void search() {
               mode = "searched";
               //get list to display list.xhtml
               ..................
               }
              ..........
              }

              @Stateful
              @Name("regAction")
              @Restrict("#{identity.loggedIn}")
              public class RegAction implements IRegAction {
              
               ...........
               @In(required = false)
               @Out(required = false, scope = ScopeType.PAGE)
               private String mode;
              
               public void init() {
               if ("searched".equals(mode)) {
               ....
               } else {
               ....
               }
               }
              }
              

              pages.xml
              <page view-id="/list.xhtml" login-required="true">
               <navigation from-action="#{listAction.search}">
               <redirect view-id="/list.xhtml" />
               </navigation>
               <navigation from-action="#{regAction.init}">
               <begin-conversation flush-mode="manual" />
               <redirect view-id="/register.xhtml" />
               </navigation>
              </page>
              


              • 4. Re: Why PAGE context variable = NULL
                pmuir

                Those are two different pages, so you won't have the same page context for both pages... (i.e. what you are trying to do is flawed from a design perspective)

                • 5. Re: Why PAGE context variable = NULL
                  nguyenhaugiang

                  Pete,
                  I have exactly same problem.

                  In the case action A render page a, from page a call an method of action B:
                  A -> a -> B
                  A and B share the same page scope

                  next we do the same thing:
                  B -> b -> C
                  B and C share the same page scope

                  So, if we declare page scope field with @in @out in A, B, C,
                  we can pass data from A -> B -> C by using page scope
                  is that right?

                  The problem is that in flow A -> a -> B -> b -> C,
                  page context is destroy if after invoking B,
                  page flow is redirected to page b.
                  (Page context still "alive" if render)

                  The difference is render(OK) and redirect(fail).

                  Any help would be appreciated.
                  Thanks,
                  Giang

                  • 6. Re: Why PAGE context variable = NULL
                    pmuir

                    Yes, this is to be expected. After calling B you do a redirect to another page, hence the page context changes. (B is called in the context of A). Doing a redirect is essentially a call to a new page. You should use the conversation scope for passing a variable through a sequence of logically connected pages.

                    • 7. Re: Why PAGE context variable = NULL
                      nguyenhaugiang

                      Thank you for your reply.

                      As in http://www.jboss.com/index.html?module=bb&op=viewtopic&t=124426,
                      we want to maintain state through a sequence of pages, but do not share SMPC.

                      Page Context var can solve our case?

                      • 8. Re: Why PAGE context variable = NULL
                        pmuir

                        No, the page context only lasts as long as a page. You could use a conversation and a standard PC injected with @PersistenceContext to get a new PC for each request. This is really an anti-pattern with Seam though, and you would be better understanding lazy loading properly.