3 Replies Latest reply on Apr 27, 2010 12:00 PM by sappo

    Seam bean not created in any context

    lee3star.lee3star.gmail.com

      This might be a very simple problem, but I've been stuck on this for a couple of days.


      I was trying the sample app which one registers to the web site and the user info's stored to DB. I chose to implement this using JPA entity bean and Stateless session bean.


      Here's my User entity annotations:



      @Entity
      @Table(name = "USER", uniqueConstraints = {
                @UniqueConstraint(columnNames = "username"),
                @UniqueConstraint(columnNames = "email_address") })
      @Name("newUser")
      @Scope(ScopeType.EVENT)
      public class User implements Serializable {
      
      ...
           @Column(name = "email_address", nullable = false)
           @Email
           @NotNull
           public String getEmailAddress() {
                return emailAddress;
           }
      ...
      



      and here's my xhtml snippet:


          <rich:panel>
              <f:facet name="header">Register</f:facet>
              <h:form id="registerActionForm" styleClass="edit">
                     <s:decorate id="nameField" template="layout/edit.xhtml">     
                          <ui:define name="label">Name</ui:define>
                          <h:inputText id="name" value="#{newUser.name}" required="true"/>
                     </s:decorate>
                     <s:decorate id="emailAddressField" template="layout/edit.xhtml">     
                          <ui:define name="label">Email Address</ui:define>
                          <h:inputText id="emailAddress" value="#{newUser.emailAddress}" required="true"/>
                     </s:decorate>
                              ...
                     <div class="actionButtons">
                          <s:button id="registerAction" value="register" action="#{registerAction.register}"/>
                     </div>
              </h:form>
          </rich:panel>



      And here's my action bean:


      @Stateless
      @Name("registerAction")
      public class RegisterActionBean implements RegisterAction
      {
          @Logger private Log log;
      
          @In StatusMessages statusMessages;
          
         
          public String register()
          {
              // implement your business logic here
              log.info("registerAction.registerAction() action called");
              User newUser = (User)Contexts.lookupInStatefulContexts("newUser");
              statusMessages.add("registerAction");
              if (newUser == null){
                   log.info("newUser not passed");
                   return null;
              }        
              log.info("register success");
              return "success";
          }
      
          // add additional action methods
      
      }



      I always got the message 'newUser not passed' which I don't know why.


      In my understanding:


      1) validation should occur before the action component is invoked. it doesn't happen in my case, as my hibernate validation for email never got called.
      2) the entity component should be created automatically, but I cannot find it from any scope context.


      There must be something missed. Please advise.