3 Replies Latest reply on Jul 25, 2008 9:07 AM by Eric H

    Bean in Conversation is null after 2nd Page

    some one Newbie

      I have an application with a registration wizard and an action (MemberRegistrationAction) bean that has a member bean (Member). It's very similar to the SeamSpace example. My problem is that the Member bean is set to null after the following set of steps:


      1.) register.html calls MemberRegistrationAction.start which creates a new Member object (object is not null) ... forward onto:
      2.) register1.html calls MemberRegistrationAction.agreeToLicense which accesses the Member object ... sucessfully edits some data in Member ... forward onto:
      3.) register2.html calls MemberRegistrationAction.finalize which tries to access the member object. However the member object is now null. It's been somehow removed.


      I'm running in Tomcat 6, Seam 2.0.2.


      My pages.xml file is:



      <?xml version="1.0" encoding="UTF-8"?>
      <pages xmlns="http://jboss.com/products/seam/pages"  
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://jboss.com/products/seam/pages 
      http://jboss.com/products/seam/pages-2.0.xsd"
      
             no-conversation-view-id="/index.xhtml"
                       login-view-id="/index.xhtml">
      
        <conversation name="regmem"
          parameter-name="memberID"
          parameter-value="#{memberreg.newMember.memberID}"/>
      
        <page view-id="/register.xhtml">
          <navigation from-action="#{memberreg.start}">
            <begin-conversation join="true" conversation="regmem"/>
            <rule if="#{memberreg.started}">
              <redirect view-id="/register1.xhtml"/>
            </rule>
          </navigation>
          <navigation>
            <rule if="#{memberreg.agree}">
              <redirect view-id="/register2.xhtml"/>
            </rule>
            <rule if="#{memberreg.started and not memberreg.agree}">
              <redirect view-id="/register1.xhtml"/>
            </rule>
            <rule if="#{identity.loggedIn}">
              <redirect view-id="/memberadmin.xhtml"/>
            </rule>
          </navigation>
        </page>
      
        <page view-id="/register1.xhtml" conversation-required="true"
          conversation="regmem">
          <restrict>#{memberreg.started}</restrict>
          <navigation from-action="#{memberreg.agreeToLicense}">
            <rule if="#{memberreg.agree}">
              <redirect view-id="/register2.xhtml"/>
            </rule>
          </navigation>
          <navigation from-action="#{memberreg.cancel}">
            <end-conversation/>
            <rule if="#{not memberreg.agree}">
              <redirect view-id="/index.xhtml"/>
            </rule> 
          </navigation>
          <navigation>
            <rule if="#{identity.loggedIn}">
              <redirect view-id="/memberadmin.xhtml"/>
            </rule>
          </navigation>
        </page>
      
        <page view-id="/register2.xhtml" conversation-required="true"
          conversation="regmem">
          <restrict>#{memberreg.agree}</restrict>
          <navigation from-action="#{memberreg.finalize}">
            <rule if="#{memberreg.completed}">
              <redirect view-id="/index.xhtml"/>
              <end-conversation/>
            </rule>
            <rule if="#{not memberreg.completed}">
              <redirect view-id="/register2.xhtml"/>
            </rule>
          </navigation>
          <navigation>
            <rule if="#{identity.loggedIn}">
              <redirect view-id="/memberadmin.xhtml"/>
            </rule>
          </navigation>
        </page>
      </pages>




      register.html has the following button:



      <h:commandButton value="Register" action="#{memberreg.start}">
           <s:conversationName value="regmem"/>
           <s:conversationPropagation type="join"/>
      </h:commandButton>



      register1.html has the following button:



      <h:commandButton id="agreebut1" value="Agree"
           action="#{memberreg.agreeToLicense}">
           <s:conversationName value="regmem"/>
           <s:conversationPropagation type="join"/>
      </h:commandButton> 



      register2.html has the following button:



      <h:commandButton id="finalize" value="Submit"
           action="#{memberreg.finalize}">
           <s:conversationName value="regmem"/>
           <s:conversationPropagation type="join"/>
      </h:commandButton>



      My MemberRegistrationAction.java class is:



      @Scope(CONVERSATION)
      @Name("memberreg")
      public class MemberRegistrationAction implements Serializable
      {
      ...
          @Out(required = false) @In(required = false)
          private Member newMember;
      
      ...
      }



      The methods listed in MemberRegistrationAction do not have any annotations in them.


      Any help would be greatly appreciated.


      -Arron

        • 1. Re: Bean in Conversation is null after 2nd Page
          some one Newbie

          To further exasperate the issue, I've used the chapter 6 conversation list example  to print out all conversations (FYI: you have to remember to put the description element in the page element in your pages.xml file in order to actually view your conversations).


          All of the conversations are correctly showing up with the correct id values (not changing from page-to-page) so I know the conversations are okay.


          Also, I am using a natural conversations (see the above pages.xml file).

          • 2. Re: Bean in Conversation is null after 2nd Page
            some one Newbie

            I feel like a complete idiot. A seasoned Java programmer and what did I do? I called my finalize method ... finalize. As in:



            public void finalize() { ... }




            Oops! Seam was calling my class's super class finalize method (java.lang.Object) and of course the object didn't appear, it was garbage collected! Major d'oh moment!


            Anyways, the upshot is that I have natural conversations running just fine. The registration process works quite well, I'm totally jazzed on this Seam stuff. As I sit back and reflect I realize that had I coded all of this stuff by myself (i.e., without using Seam, Hibernate) I would most likely have written about 2 KLOCs by now. I think I've written about 40 lines thus far.


            Gotta love this framework!

            • 3. Re: Bean in Conversation is null after 2nd Page
              Eric H Novice

              Arron Ferguson wrote on Jul 25, 2008 08:43:

              Anyways, the upshot is that I have natural conversations running just fine. The registration process works quite well, I'm totally jazzed on this Seam stuff. As I sit back and reflect I realize that had I coded all of this stuff by myself (i.e., without using Seam, Hibernate) I would most likely have written about 2 KLOCs by now. I think I've written about 40 lines thus far.

              Gotta love this framework!


              That's right!  Once you get it all working, you can do amazing things in a tiny fraction of the code it would take otherwise.


              And, to add another layer of coolness, you have an app that probably doesn't need any modifications AT ALL to run on all the major databases.  Compare that to keeping half a dozen SQL variants in sync and bug tested.