7 Replies Latest reply on Jun 12, 2007 12:54 PM by drab

    Beginner Question

    drab

      Hi,

      I'm trying for a few days now to get the most basic things to work with Seam, but I fail miserably. I'm highly frustrated and of course try to find the missing piece of information here that I'm apparently lacking to get this to work.

      I created a project with seam-gen and added a page register.xml that contains this:

       <h:form id="registerForm" rendered="#{userRegistration.account==null}">
      
       <h:outputLabel for="realName">name:</h:outputLabel>
       <h:inputText value="#{userRegistration.account.realName}" size="30" id="realName"/><br/>
       <h:outputLabel for="email">email: </h:outputLabel>
       <h:inputText value="#{userRegistration.account.email}" id="email" size="30"/><br/>
       <h:commandButton type="submit" value="register" action="#{userRegistration.register}"/>
      
       </h:form>
      
      
       <h:form id="otherForm" rendered="#{userRegistration.account!=null}">
       you have been registered as #{userRegistration.account.realName}. You should receive an email with your password.
       </h:form>
      
      


      I have my LoginAccount entity:



      @Entity
      @Name("LoginAccount")
      public class LoginAccount implements Serializable {
      
      
       @Id
       @GeneratedValue
       protected int id;
       protected String realName;
       @Email
       protected String email;
      
       public LoginAccount() {
      
       }
      ...+setter and getters
      


      and I have my "userRegistration" session bean:

      @Stateful
      @Name("userRegistration")
      @Scope(ScopeType.SESSION)
      public class RegistratorAction implements Registrator {
      
      
       @Logger
       private Log log;
      
       @In @Out
       public LoginAccount account;
      
       @PersistenceContext(type = EXTENDED)
       private EntityManager em;
      
      
       public String register() {
      
       log.info("persisting #0", account.toString());
       em.persist(account);
       return null;
       }
      


      but when I click on the link to this page, I get following error:

      /register.xhtml @19,80 rendered="#{userRegistration.account==null}": Bean: org.javassist.tmp.java.lang.Object_$$_javassist_39, property: account
      


      so I changed all occurences of "userRegistration.account" into "account" thinking it might be in a global context. Now, the site displays and I can enter my name and email. But when I press the submit button, nothing happens. "register()" is not called on the Session, and neither "getRealName()" or "setRealName()" of the entity are called.

      Could somebody give me a hint what I'm doing wrong? I'm pretty frustrated that I can't even get a helloWorld-type application to work.

      thanks
      Dirk

        • 1. Re: Beginner Question
          fernando_jmt

          At first glance I can see one wrong thing, your entity component name is "LoginAccount", so if you want to biject it, you should declare it as follows:

          @In @Out
           public LoginAccount LoginAccount;
          

          or

          @In(value="#{LoginAccount}") @Out(value="#{LoginAccount}")
           public LoginAccount LoginAccount;
          



          BTW, check whether your interface has the correct methods corresponding to component it is implementing it.

          HTH.



          • 2. Re: Beginner Question
            drab

            hmmm.... I noticed that, but I intentionally didn't want to give the instance the same name as the entity. What if I wanted to deal with 2 LoginAccounts in my conversation?

            I know the user registration is not a good example where I might want to have 2 instances of the same entity class, but it is definitely not an uncommon scenario.

            So do I understand it right that if I want to use an entity in my jsf page, then I can never have 2 of the same kind in a conversation?

            Dirk

            • 3. Re: Beginner Question
              gavin.king

              Well, I think I can spot at least 3 errors to begin with:

              (1) The value bindings should be #{account==null}, #{account.realName}, etc, OR you need to get rid of the @Out annotation, and add a getAccount() method.

              (2) @Name("LoginAccount") should be @Name("loginAccount"), names are supposed to be initial lowercase.

              (3) You are trying to bind inputs to a value that is outjected only when the action method is called, which happes *after* update model values.

              Now, there is an example *exactly like this* on the very first page of the documentation, so why not just copy that. It looks like you're trying to jump in and write code without first learning the semantics of the JSF lifecycle, Seam bijection, etc.

              • 4. Re: Beginner Question
                fernando_jmt

                Typo in the second option I mentioned, it should be:

                 @In(value="#{LoginAccount}")
                 @Out(value="#{LoginAccount}")
                 public LoginAccount account;
                


                • 5. Re: Beginner Question
                  gavin.king

                   

                  hmmm.... I noticed that, but I intentionally didn't want to give the instance the same name as the entity. What if I wanted to deal with 2 LoginAccounts in my conversation?

                  I know the user registration is not a good example where I might want to have 2 instances of the same entity class, but it is definitely not an uncommon scenario.

                  So do I understand it right that if I want to use an entity in my jsf page, then I can never have 2 of the same kind in a conversation?



                  Trying to dream up really complex cases is exactly the WRONG way to go about writing helloworld. It's about as smart as intentionally shooting yourself in the foot. Once you have actually mastered helloworld, and gone back to reading the documentation, you will find suggestions for how to handle this problem using eg: @Roles, or a manager or factory component.

                  But you don't have that problem now, and the solution you have tried is incorrect, so why not learn the basics first?

                  • 6. Re: Beginner Question
                    gavin.king

                    (In my experience of helping thousands of people learn Hibernate and Seam, early frustration is always a result of trying to do too much at once, and ignoring the resources - docs, examples - that already exist.)

                    • 7. Re: Beginner Question
                      drab

                      Hello Gavin,

                      thanks for your response and I can understand your frustration about dealing with people that are a bit too enthusiastic at start. It's just that no 2 developers write the same HelloWorld application. And since Seam looked easy to me, I tried to do HelloWorld + 10%. Reading a lot of documentation unfortunately doesn't save from making programming errors.

                      Dirk