1 Reply Latest reply on Mar 4, 2010 11:35 AM by andy jovi

    Register tutorial basic error javax.el.PropertyNotFoundException (Target Unreachable)

    andy jovi Newbie


      registration.xhtml value="#{register.user.firstName}": Target Unreachable, 'user' returned null on ...
      javax.el.PropertyNotFoundException:

      Registration.java

      import javax.ejb.Remove;
      import javax.persistence.EntityManager;

      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.End;
      import org.jboss.seam.annotations.Observer;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.faces.FacesMessages;
      import org.jboss.seam.security.Identity;
      import org.jboss.seam.security.RunAsOperation;
      import org.jboss.seam.security.management.IdentityManager;
      import org.jboss.seam.security.management.JpaIdentityStore;

      import com.extsf.model.user.User;
      import com.extsf.model.user.UserAccount;

      @Name("register")
      @Scope(ScopeType.CONVERSATION)
      public class Registration {
           
           private User user;
           private UserAccount newAccount;
           private String username;
           private String password;
           private String passwordConfirmation;
           private boolean passwordVerified;
           
           @In
           EntityManager entityManager;

           @In
           Identity identity;
           
           @In
           IdentityManager identityManager;
           
           @Begin
           public void createUser()
           {
                user = new User();
           }

           public void verifyPassword()
           {
                passwordVerified = (passwordConfirmation != null && passwordConfirmation.equals(password));
                if (!passwordVerified)
                {
                     FacesMessages.instance().addToControl("confirmPassword", "Passwords don not match");
                }
           }
           
           @Observer(JpaIdentityStore.EVENT_USER_CREATED)
           public void userAccountCreated(UserAccount account)
           {
                account.setUser(user);
                this.newAccount = account;
           }
           
           @End
           public void createUserAccount()
           {
                entityManager.persist(user);
                new RunAsOperation()
                {
                     public void execute()
                     {
                          identityManager.createUser(username, password);
                          identityManager.grantRole(username, "user");
                     }
                }.addRole("admin").run();
                
                newAccount.setUser(user);
                newAccount = entityManager.merge(newAccount);
                
                // Automatically, sign the user in
                identity.getCredentials().setUsername(username);
                identity.getCredentials().setPassword(password);
                identity.logout();
           }
           
           public User getUser()
           {
                return user;
           }
           
           public String getUsername()
           {
                return username;
           }
           
           public void setUsername(String username)
           {
                this.username = username;
           }
             
           public String getPassword()
           {
                return password;
           }
             
           public void setPassword(String password)
           {
                this.password = password;
           }
             
           public String getPasswordConfirmation()
           {
                return passwordConfirmation;
           }
             
           public void setPasswordConfirmation(String passwordConfirmation)
           {
                this.passwordConfirmation = passwordConfirmation;
           }
             
           public boolean isPasswordVerified()
           {
                return passwordVerified;
           }
             
           @Destroy @Remove
           public void destroy() {}
      }

      registration.xhtml

                                  <h:inputText id="firstname" required="true"
                                               value="#{register.user.firstName}"/>

      BTW, i have the seam.properties in WEB-INF\classes and components.xml in WEB-INF of the war but still cannot solve this. Please advice.

        • 1. Re: Register tutorial basic error javax.el.PropertyNotFoundException (Target Unreachable)
          andy jovi Newbie

          Sorry let me reformat the text a bit:


          registration.xhtml @32,78 value="#{register.user.firstName}": Target Unreachable, 'user' returned null on 'com.extsf.action.Registration_$$_javassist_seam_2'
          javax.el.PropertyNotFoundException: /registration.xhtml
          



          Registration.java


          import javax.ejb.Remove;
          import javax.persistence.EntityManager;
          
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.ScopeType;
          import org.jboss.seam.annotations.Begin;
          import org.jboss.seam.annotations.Destroy;
          import org.jboss.seam.annotations.End;
          import org.jboss.seam.annotations.Observer;
          import org.jboss.seam.annotations.Scope;
          import org.jboss.seam.annotations.In;
          import org.jboss.seam.faces.FacesMessages;
          import org.jboss.seam.security.Identity;
          import org.jboss.seam.security.RunAsOperation;
          import org.jboss.seam.security.management.IdentityManager;
          import org.jboss.seam.security.management.JpaIdentityStore;
          
          import com.extsf.model.user.User;
          import com.extsf.model.user.UserAccount;
          
          @Name("register")
          @Scope(ScopeType.CONVERSATION)
          public class Registration {
                  
                  private User user;
                  private UserAccount newAccount;
                  private String username;
                  private String password;
                  private String passwordConfirmation;
                  private boolean passwordVerified;
                  
                  @In
                  EntityManager entityManager;
          
                  @In
                  Identity identity;
                  
                  @In
                  IdentityManager identityManager;
                  
                  @Begin
                  public void createUser()
                  {
                          user = new User();
                  }
          
                  public void verifyPassword()
                  {
                          passwordVerified = (passwordConfirmation != null && passwordConfirmation.equals(password));
                          if (!passwordVerified)
                          {
                                  FacesMessages.instance().addToControl("confirmPassword", "Passwords don not match");
                          }
                  }
                  
                  @Observer(JpaIdentityStore.EVENT_USER_CREATED)
                  public void userAccountCreated(UserAccount account)
                  {
                          account.setUser(user);
                          this.newAccount = account;
                  }
                  
                  @End
                  public void createUserAccount()
                  {
                          entityManager.persist(user);
                          new RunAsOperation()
                          {
                                  public void execute()
                                  {
                                          identityManager.createUser(username, password);
                                          identityManager.grantRole(username, "user");
                                  }
                          }.addRole("admin").run();
                          
                          newAccount.setUser(user);
                          newAccount = entityManager.merge(newAccount);
                          
                          // Automatically, sign the user in
                          identity.getCredentials().setUsername(username);
                          identity.getCredentials().setPassword(password);
                          identity.logout();
                  }
                  
                  public User getUser()
                  {
                          return user;
                  }
                  
                  public String getUsername()
                  {
                          return username;
                  }
                  
                  public void setUsername(String username)
                  {
                          this.username = username;
                  }
                     
                  public String getPassword()
                  {
                          return password;
                  }
                     
                  public void setPassword(String password)
                  {
                          this.password = password;
                  }
                     
                  public String getPasswordConfirmation()
                  {
                          return passwordConfirmation;
                  }
                     
                  public void setPasswordConfirmation(String passwordConfirmation)
                  {
                          this.passwordConfirmation = passwordConfirmation;
                  }
                     
                  public boolean isPasswordVerified()
                  {
                          return passwordVerified;
                  }
                     
                  @Destroy 
                  @Remove
                  public void destroy() {}
          }
          



          registration.xhtml


                                      <h:inputText id="firstname" required="true"
                                                   value="#{register.user.firstName}"/>
          
          
          BTW, i have the seam.properties in WEB-INF\classes and components.xml in WEB-INF of the war but still cannot solve this. Please advice.
          
          



          Thank you,
          jovi