I'm just starting learning CDI and Java EE 6 but I found this piece of code that I want to fully understand.
@Stateful
@Model
public class MemberRegistration {
@Inject
private EntityManager em;
@Inject
private Event<Member> memberEventSrc;
private Member newMember;
@Produces
@Named
public Member getNewMember() {
return newMember;
}
}
Then... I saw that a jsf page referenced this newMember object like this:
<h:inputText value=#{newMember.name}/>
So my question is : It doesn't matter if I put an @Named annotation inside an variable of any object, it will be accessible anyway from JSF code?
Also, what's the usage of @Produces in this case, and finally is @Stateful preferred over @Stateless in Java EE 6? If that's the case why?