[jboss-user] [JBoss Seam] - why can't inject PresistenceContext into authenticator compo

chitcool do-not-reply at jboss.com
Tue Nov 20 01:56:20 EST 2007


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;
        }

 
    }
    */
}


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4106248#4106248

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4106248



More information about the jboss-user mailing list