SeamLoginModule EntityManager injection difficulties
trickyvail Feb 23, 2007 12:28 PMI am running Seam version 1.1.6 on a JBoss 4.0.5.GA server.
While following the example from the Seam documentation (page 124) for creating a SeamLoginModule authentication method I have run into the following error:
09:37:41,228 ERROR [SeamLoginModule] Error invoking login method javax.faces.el.EvaluationException: Exception while invoking expression #{authenticator.authenticate} at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153) at org.jboss.seam.actionparam.ActionParamBindingHelper.invokeTheExpression(ActionParamBindingHelper.java:59) at org.jboss.seam.actionparam.ActionParamMethodBinding.invoke(ActionParamMethodBinding.java:74) [SNIP] at java.lang.Thread.run(Thread.java:595) Caused by: org.jboss.seam.RequiredException: In attribute requires value for component: authenticator.entityManager at org.jboss.seam.Component.getInstanceToInject(Component.java:1920) at org.jboss.seam.Component.injectFields(Component.java:1386) at org.jboss.seam.Component.inject(Component.java:1156) [SNIP] ... 59 more
This suggests that Seam is unable to locate and inject the entityManager by its component name. The relevant java bean that the login component is calling is as follows:
@Name("authenticator") public class Authenticator { @In EntityManager entityManager; public boolean authenticate() { return true; } }
For completeness here, is the form that is calling the validation:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" template="layout/template.xhtml"> <ui:define name="body"> <h1>Login</h1> <p>Please login using any username and password</p> <h:messages styleClass="message"/> <h:form> <div class="dialog"> <div class="prop"> <span class="name">Username</span> <span class="value"> <h:inputText id="username" value="#{identity.username}"/> </span> </div> <div class="prop"> <span class="name">Password</span> <span class="value"> <h:inputSecret id="password" value="#{identity.password}"/> </span> </div> <div class="prop"> <span class="name">Remember me</span> <span class="value"> <h:selectBooleanCheckbox id="rememberMe" value="#{identity.rememberMe}"/> </span> </div> </div> <div class="actionButtons"> <h:commandButton value="Login" action="#{identity.login}"/> </div> </h:form> </ui:define> </ui:composition>
I have also tried to annotate the EntityManager object in the following ways:
@In("entityManager") EntityManager entityManager; @In(value="entityManager") EntityManager entityManager;
but have recieved the same error.
My configuration was generated by seam-gen and the authenticate method works fine until I try to inject an EntityManager into the component.
I will create a Stateful Session Bean in order to try to inject the EntityManager by the EJB3.0 annotation @PersistenceContext rather than Seam @In annotation.
Could this be caused by a filter loading order? I've looked at web.xml and it does not seem to be the cause. I think too that the identity component is a Seam component (ie. eats its own dogfood), therefore should not be a problem, Maybe the identity component is instantiated before other components like the entity manager?
P.S. Thank you Gavin King for all your past helpful answers.