7 Replies Latest reply on Oct 24, 2006 9:31 PM by bsheward

    Seam Problem!!! URGENT, please

    argomauro

      I've create a new seam application that insert in a MysqlDb an Object named "utente" and another named "profilo". I've create a Steteful java class that insert this objects and it's work fine.
      Subsequently i've create a page for implement the Login functionality with another Stateful java class and only in this case the application return an error:

      Caused by: org.jboss.seam.InstantiationException: Could not instantiate Seam component: managerLogin
       at org.jboss.seam.Component.newInstance(Component.java:735)
       at org.jboss.seam.Component.newInstance(Component.java:1308)
       at org.jboss.seam.Component.getInstance(Component.java:1263)
       at org.jboss.seam.Component.getInstance(Component.java:1246)
       at org.jboss.seam.jsf.SeamVariableResolver.resolveVariable(SeamVariableResolver.java:44)
       at org.apache.myfaces.el.ValueBindingImpl$ELVariableResolver.resolveVariable(ValueBindingImpl.java:569)
       at org.apache.commons.el.NamedValue.evaluate(NamedValue.java:124)
       at org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(ValueBindingImpl.java:450)
       at org.apache.myfaces.el.MethodBindingImpl.resolveToBaseAndProperty(MethodBindingImpl.java:180)
       at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:114)
       ... 25 more
      Caused by: javax.naming.NameNotFoundException: ManagerLogin not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at org.jboss.seam.Component.instantiate(Component.java:774)
       at org.jboss.seam.Component.newInstance(Component.java:731)
      


      My Stateful class is:
      @Stateful
      @Name("managerLogin")
      @Scope(ScopeType.SESSION)
      public class ManagerLogin implements Serializable {
      
       @In(create=true)
       private EntityManager em;
      
       @In(value = "login")
       private EntityLogin login = new EntityLogin();
      
       @In(value = "utente")
       @Out
       private EntityUtente utente;
      
       @Logger
       private Log log;
      
       public String login() {
       List results = em.createQuery(
       "from utente where username=:username and password=:password")
       .setParameter("username", login.getUsername())
       .setParameter("password", login.getPassword())
       .getResultList();
       if (results.size() == 0) {
       FacesMessages.instance().addFromResourceBundle("LoginNonValido");
       return null;
       } else {
       Contexts.getSessionContext().set("loggedIn", true);
       utente = (EntityUtente) results.get(0);
      
       return "home" ;
       }
       }
      
       public String logout() {
       Contexts.getSessionContext().remove("loggedIn");
       Seam.invalidateSession();
       return "home";
       }
      
       @Remove
       @Destroy
       public void destroy() {
       }
      }
      


      My jsp page is:
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <html>
      <head>
      <title><h:outputText value="#{messages.Login}" /></title>
      
      </head>
      <body>
      <f:view>
       <h:form>
      
       <h1><h:outputText value="#{messages.Login}" /></h1>
      
      
       <h:outputText value="#{messages.LoginDetails}" />
      
       <table>
       <tr>
       <td><h:inputText value="#{login.username}" id="username" /></td>
       </tr>
       <tr>
       <td><h:inputText value="#{login.password}" id="password" /></td>
       </tr>
      
       <h:commandButton type="submit" value="#{messages.Login}"
       action="#{managerLogin.login}" />
       <h:commandButton type="submit" value="#{messages.Register}"
       action="insertUtente" />
       </h:form>
      
      </f:view>
      </body>
      
      </html>
      

      And the login bean is an object but not persistent that contains the user data entry for login:
      @Name("login")
      public class EntityLogin implements Serializable {
      
       private static final long serialVersionUID = 188141350071143953L;
      
       public EntityLogin(String password, String username) {
       this.username = username;
       this.password = password;
       }
      
       public EntityLogin() {
       }
      
       private String username;
      
       private String password;
      
       @NotNull
       @Length(max = 10)
       public String getUsername() {
       return this.username;
       }
      
       public void setUsername(String username) {
       this.username = username;
       }
      
       @Length(max = 15)
       @NotNull
       public String getPassword() {
       return this.password;
       }
      
       public void setPassword(String password) {
       this.password = password;
       }
      
      }
      

      The login bean is the new entry in this code but precedently i've create an instance of the user in the ManagerLogin class but i was a different error,
      componet not find ...


      An example of the Stateful that work fine:
      @Entity
      @Name("utente")
      @Scope(SESSION)
      @Table(name="utente")
      public class EntityUtente implements Serializable {
      
      
       private static final long serialVersionUID = 188141350071143952L;
      
       public EntityUtente(Integer id, String nome, String cognome,String email,String password,String username)
       {
       this.id = id;
       this.nome = nome;
       this.cognome = cognome;
       this.email = email;
       this.username = username;
       this.password = password;
       }
      
       public EntityUtente(){}
      
       private Integer id;
       private String username;
       private String nome;
       private String cognome;
       private String password;
       private String email;
      
       public void setId(Integer id) {
       this.id = id;
       }
      
       @Id @GeneratedValue
       public Integer getId() {
       return id;
       }
      
       @NotNull
       @Length(max=10)
       public String getUsername() {
       return this.username;
       }
      
       public void setUsername(String username) {
       this.username = username;
       }
      
       public void setNome(String nome) {
       this.nome = nome;
       }
      
       @Length(max=100) @NotNull
       public String getNome() {
       return nome;
       }
      
       public void setCognome(String cognome) {
       this.cognome = cognome;
       }
       @Length(max=100) @NotNull
       public String getCognome() {
       return cognome;
       }
      
      
       @Length(max=15) @NotNull
       public String getPassword() {
       return this.password;
       }
      
       public void setPassword(String password) {
       this.password = password;
       }
      
       public void setEmail(String email) {
       this.email = email;
       }
       @Email
       public String getEmail() {
       return email;
       }
      
      }
      
      


      For me it is a incomprensibile error, because others two similar cases work (ManagerUtente,ManagerProfilo)and the login action not.


      Thanks for help....

        • 1. Re: Seam Problem!!! URGENT, please
          mnrz

          I think this error occurs when Seam can not instantiate your entity defined inside your backing bean.
          in your case, the Seam could not bind EntityLogin so entire LoginManager instantiation has failed.

          maybe you should put @Entity at top of your EntityLogin.

          hope this help

          • 2. Re: Seam Problem!!! URGENT, please
            gavin.king

            Your stateful session bean is missing its local interface.

            • 3. Re: Seam Problem!!! URGENT, please

               

              public class ManagerLogin implements Serializable {
              


              Your session bean does not define any interfaces.

              Regards

              fhh

              P.S.: Also make sure that you declare the seam interceptor in components.xml or by using @interceptor.


              • 4. Re: Seam Problem!!! URGENT, please
                argomauro

                I've omitted the local interface in my session bean ManagerLogin and i discovery that the method that can invoke from a jsf page is only the method in the session bean that override the interface method.

                Thanks for your time!
                Bye

                • 5. Re: Seam Problem!!! URGENT, please

                   


                  I've omitted the local interface in my session bean ManagerLogin and i discovery that the method that can invoke from a jsf page is only the method in the session bean that override the interface method.


                  I don't want to be impolite but I'm not sure if you have grasped the central concept of session beans. You HAVE TO degine those interfaces. Otherwise it won't work. This is not Seam or JSF specific.

                  Regards

                  fhh

                  • 6. Re: Seam Problem!!! URGENT, please
                    argomauro

                    Thanks for your suggestions. I'll deepen the SessionBean argument!

                    • 7. Re: Seam Problem!!! URGENT, please

                      In defence of argomauro, I've made the same mistake.

                      Sure, when dealing with EJB 2.1 and JSP pages, everything had to go through interfaces, but Seam is somehow able to inject values directly into the session beans themselves (the implementation of the interfaces) so its easy to slip into thinking that it ought to be able to call the methods in the session beans themselves, rather than the interfaces.

                      Seeing the answers to posts like this is helping me understand better how Seam works, and that really helps to develop using it.

                      Anyway, thanks for helping out, it really is appreciated!