2 Replies Latest reply on Nov 20, 2007 6:52 AM by Shane Bryzak

    why can't inject PresistenceContext into authenticator compo

    Chit Ko Newbie

      Please comment on how to inject entityManager into Seam component action. And explain the way to call em.createQuery to check the db.

      thank in advance.

      package com.nov.session;

      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.security.Identity;
      import org.jboss.seam.faces.FacesMessages;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import javax.persistence.NoResultException;
      import java.util.List;
      import javax.ejb.Stateless;
      import static org.jboss.seam.ScopeType.EVENT;

      import com.nov.entity.Customers;
      @Name("authenticator")
      public class Authenticator {
      @Logger
      Log log;
      @In FacesMessages facesMessages;
      @In
      Identity identity;
      public boolean authenticate() {
      return true;
      }
      /*
      @PersistenceContext
      private EntityManager em;

      public boolean authenticate() {
      log.info("authenticating #0...^^^^^^^^username........................", identity.getUsername());
      log.info("authenticating #0...^^^^^^^^^password........................", identity.getPassword());
      try {
      Customers customers = (Customers)em.createQuery("select u from Customers u where customers_email_address=:email_address and customers_password=:password")
      .setParameter("email_address", identity.getUsername())
      .setParameter("password", identity.getPassword())
      .getSingleResult();

      if (customers == null) {
      return false;
      }
      identity.addRole("customers");
      return true;
      } catch (NoResultException ex){
      log.info("authenticating #0...^^^^^^^^NORESULTEXCEPTION........................", ex.toString());
      facesMessages.add("Invaild username and password. Username is your registered email address"); return false;
      }


      }
      */
      }