Help needed with Weld,EJB,JSF
scaroo Nov 27, 2009 3:19 PMHi everybody,
I am hitting an issue I cannot resolve alone, for which I'd be very glad and thankful getting some help and input.
I am trying to implement a registration system in JSF using a service exposed via Weld. The service is a staful session bean exposed via CDI to jsf. It has a producer method, producing a new request-scoped User instance, and a register
method, persisting the jsf-filled user instance. So far so good (or is it?)
The thing is that any call from jsf to the register
method raises an IllegalStateException. Here is the code
Bean :
@Named("registration") @SessionScoped @Stateful public class RegistrationService implements Serializable { @Inject @Named("newUser") User newUser; @Inject @UserDatabase EntityManager em; @Produces @RequestScoped @Named("newUser") public User getNewUser() { return new User(); } public String register() { em.persist(newUser); return null;//"registerConfirmation"; } }
JSF page snippet :
<h:form> <h1><h:outputText value="Create/Edit"/></h1> <h:panelGrid columns="3"> <h:outputLabel value="Username:" for="username" /> <h:inputText id="username" value="#{newUser.username}" title="Username" /> <h:message for="username"/> <h:outputLabel value="Email:" for="email" /> <h:inputText id="email" value="#{newUser.email}" title="Email" /> <h:message for="email"/> <h:outputLabel value="Password:" for="password" /> <h:inputSecret id="password" value="#{newUser.password}" title="Password" /> <h:message for="password"/> <h:commandButton value="Ok" action="#{registration.register}"/> </h:panelGrid> </h:form>
Does anything seems weird to you ?
What would you advice as best practice (regarding Statefulness, Scoping...) to implement a registration system ?
Anyway, thanx to ya if you read this far :)