3 Replies Latest reply on Nov 14, 2006 12:59 PM by Gavin King

    Problem with page actions, @Begin and stateful beans

    Peter Brewer Novice

      I'm using seam 1.1beta2 (although the error occurs in 1.0.1.GA as well). I have defined some page actions to setup some virtual pages so that two different user types (standard and special) get redirected to a single sign-up page.

      So, when a user goes to standardRegistration.faces they:
      1. hit the virtualStandardRegistration page action method, which
      2. creates a new User object and
      3. redirects, via the returned jsf outcome, to memberRegistration.faces
      4. which in turn calls the pageLoading method.

      However, the stateful session bean invoked at step 1 is not the same as the stateful session bean invoked at 4. Consequently, the user object created at step 2 is null and it redirects back to standardRegistration and the whole process loops infinitely.

      I should also mention there is another page action that checks the login credentials, but that method always returns the null outcome in this situation, so in theory it can be ignored.

      Shouldn't these session beans be the same instance over the different invocations? If you need any more information, please let me know and I'll post what I can.

      Cheers, Pete

      pages.xml

      <pages>
       <page view-id="/*" action="#{login.loginCheck}">Login Check</page>
      
       <page view-id="/standardRegistration.xhtml" action="#{memberDetailsManager.virtualStandardRegistration}">Standard Registration</page>
      
       <page view-id="/specialRegistration.xhtml" action="#{memberDetailsManager.virtualSpecialRegistration}">Special Registration</page>
      
       <page view-id="/memberRegistration.xhtml" action="#{memberDetailsManager.pageLoading}">Member Registration</page>
      
      </pages>
      


      faces-config.xml
      ...
       <navigation-case>
       <from-outcome>standardRegistration</from-outcome>
       <to-view-id>/standardRegistration.xhtml</to-view-id>
       <redirect />
       </navigation-case>
      
       <navigation-case>
       <from-outcome>specialRegistration</from-outcome>
       <to-view-id>/specialRegistration.xhtml</to-view-id>
       <redirect />
       </navigation-case>
      ...
      


      MemberRegistration.java
      @Stateful
      @Scope(ScopeType.CONVERSATION)
      @Name("memberDetailsManager")
      @Intercept(InterceptionType.ALWAYS)
      @TransactionAttribute(NOT_SUPPORTED)
      public class MemberDetailsManagerAction implements MemberDetailsManager, Serializable {
      ...
       @In(required=false)
       @Out(scope = ScopeType.CONVERSATION, required=false) // required = false due to Remoting
       private User memberDetails;
      ...
       @Begin(join=true)
       public String virtualStandardRegistration() {
       String outcome = null ;
       if (isAlreadyRegistered()) {
       outcome = "memberDetails" ;
       } else {
       memberDetails = User.create(em, RoleType.Standard) ;
       newUser = true ;
       outcome = "memberRegistration" ;
       }
      
       return outcome ;
       }
      
       @Begin(join=true)
       @TransactionAttribute(REQUIRED)
       public String virtualSpecialRegistration() {
       String outcome = null ;
       if (isAlreadyRegistered()) {
       outcome = "memberDetails" ;
       } else {
       memberDetails = User.create(em, RoleType.Special) ;
       newUser = true ;
       outcome = "memberRegistration" ;
       }
      
       return outcome ;
       }
      
       public String pageLoading() {
       String outcome = null ;
       if (loggedInUser != null && memberDetails == null) {
       memberDetails = em.find(User.class, loggedInUser.getUserId()) ;
       }
      
       if (memberDetails == null) {
       outcome = "standardRegistration" ;
       }
       return outcome ;
       }
      ...