4 Replies Latest reply on May 29, 2007 2:03 PM by tmini

    Problem about EntityManager.

      hi all,
      i updated my jboss application server to 4.2.0GA and also i got seam from CVS.
      i tried to run simple seam-gen project,
      everything works fine, but when i tried to use database level authentication i got an error like this :

      javax.el.ELException: org.jboss.seam.RequiredException: In attribute requires non-null value: authenticator.em
       at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
       at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:338)
       at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
       at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
       at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
      ..................................................................
      Caused by: org.jboss.seam.RequiredException: In attribute requires non-null value: authenticator.em
       at org.jboss.seam.Component.getValueToInject(Component.java:1923)
       at org.jboss.seam.Component.injectAttributes(Component.java:1372)
       at org.jboss.seam.Component.inject(Component.java:1203)
       at org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
      
      


      i did not understand why is this object is null :(

      here is project snippets
      1. Authenticator class:
      
      @Name("authenticator")
      public class Authenticator {
      
       @Logger Log log;
      
       @In Identity identity;
      
       @In() EntityManager em;
      
       public boolean authenticate() {
       try {
       log.info("authenticating = "+identity.getUsername());
       List<Users> users = (List<Users>)em.createNamedQuery("Users.findByUserName").setParameter("userName",identity.getUsername()).getResultList();
       if (users==null || (users!=null && users.isEmpty())) {
       FacesMessages.instance().add("User #{user.username} does not exists");
       return false;
       } else {
       for (Users user : users) {
       byte dbpaswd [] = user.getUserPwd();
       String strpwd = identity.getPassword();
       MessageDigest md5 = MessageDigest.getInstance("MD5");
       md5.reset();
       md5.update(strpwd.getBytes());
       byte[] userpasswd = md5.digest();
      
       boolean result = MessageDigest.isEqual(userpasswd, dbpaswd);
       if (result) {
       identity.addRole("admin");
       return true;
       }
       }
       }
       return false;
       } catch (Exception e) {
       FacesMessages.instance().add("Could not login. System Error");
       return false;
       }
       }
      }
      


      2. Components.xml :

      <core:managed-persistence-context name="entityManager"
       auto-create="true"
       persistence-unit-jndi-name="java:/BillingEntityManagerFactory"/>
      

      3. Billing-dev-ds.xml file :
      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
       <local-tx-datasource>
       <jndi-name>BillingDatasource</jndi-name>
       <connection-url>jdbc:oracle:thin:@192.168.9.135:1521:DEVSTR</connection-url>
       <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
       <user-name>ccare</user-name>
       <password>ccare</password>
       </local-tx-datasource>
      </datasources>
      


      4. Client logi.xhtml
      <h:commandButton id="loginBtn" value="Login" action="#{identity.login}"/>
      


      what i did incorrect ?
      is it possible that reason of it is i have not this jar files into my ear file ???
      ?commons-jci-core-1.0-406301.jar
      ?commons-jci-janino-2.4.3.jar
      ?commons-lang-2.1.jar
      ?stringtemplate-2.3b6.jar


      this jars are described into documentation from where i got this example....



      Regards,
      Paata.

        • 1. Re: Problem about EntityManager.
          fernando_jmt

          You have declared SMPC as "entityManager", then you should use as follows:

          @In
          EntityManager entityManager;
          

          or (if you prefer):
          @In("#{entityManager}")
          EntityManager em;
          

          or:

          @In(value="#{entityManager}")
          EntityManager em;
          



          HTH.

          • 2. Re: Problem about EntityManager.

            Great Thanks fernando_jmt,
            did you know documentation url about new jboss seam ???
            i have another simple qusetion,
            i wrote this into my authentication bean :
            FacesMessages.instance().add("User does not exists");
            if user not exist . it works but on client side i see two messages :
            # User does not exists
            # Login failed

            how i can remove second message ??

            • 3. Re: Problem about EntityManager.

              In your messages,

              set

              org.jboss.seam.loginFailed=User does not exists
              


              • 4. Re: Problem about EntityManager.
                tmini

                If you want to produce different (more specific) failure messages from your authentication bean, you can add the faces message(s) in the bean and blank out the seam login failed message.

                if (isUsernameMissing) {
                 FacesMessages.instance().add("Username does not exist.");
                } else {
                 FacesMessages.instance().add("Invalid password provided");
                }


                org.jboss.seam.loginFailed=