2 Replies Latest reply on Jun 10, 2008 3:38 AM by Dan Allen

    Beginner question - action method and parameters

    Ryan Cuprak Newbie

      Hello,
      In working my way through the JBoss Seam book I was excited that I could 'pass' an object into my action method:
      <h:commandButton value=Join action="#{Membership.join(member)}"/ >


      However, this only appears to work if I declare a member variable in my action with create=true (action class below). This doesn't quite seem right to me. Defining a member variable defeats the purpose of passing it into the action method. Am I missing an annotation somewhere?
      I am running on Tomcat - no EJBs.


      Thanks,
      -Ryan


      @Name("Membership")
      public class Membership {
        @In(create=true)
        private Member member;
        publicc String join(Member member) {
         ...
        }
      }


      @Name("member")
      public class Member {
      // to be persisted
      }


        • 1. Re: Beginner question - action method and parameters
          Daniel Hinojosa Master

          Hey Ryan, Welcome....


          In the future can you use the tick marks so that the code can format better?  I should look something like this:


          @Name("Membership") 
          public class Membership { 
             @In(create=true) private Member member;
             public String join(Member member) { ... } 
          }
          
          @Name("member") 
          public class Member { // to be persisted } 
          



          Also, do you have other information?  Is the member coming in as null?  Is this a single page action?  Are the scopes of these objects conversations?


          You also need to make sure that parameters are
          1.Seam components
          2.Should be available on the next request.



          • 2. Re: Beginner question - action method and parameters
            Dan Allen Master

            As you learn Seam, there is something very important to remember. The argument that is passed into the method is a context variable. That means, it has to be in scope when the method is invoked. If you have to use create=true, that means that member is no longer in scope when the action executes (and Seam has to go create a brand new instance). Likely you need to store member in page or conversation scope to ensure it is still around when the action is invoked.