I have the archetype org.jboss.weld.archetypes:jboss-javaee6-webapp:1.0.1.CR2
and I try to understand the class MemberListProducer
:
@RequestScoped
public class MemberListProducer
{
@Inject @MemberRepository private EntityManager em;
private List<Member> members;
@Produces @Named public List<Member> getMembers() {return members;}
public void onMemberListChanged(@Observes(notifyObserver = Reception.IF_EXISTS)
final Member member){
retrieveAllMembersOrderedByName();
}
@PostConstruct
public void retrieveAllMembersOrderedByName()
{
//Criteria Query to fetch all members
members = em.createQuery(criteria).getResultList();
}
}
The observer is invoked from another class with memberEventSrc.fire(newMember);
, this seems clear: Once fired, the MemberListProducer
updates the list of members.
But I don't understand why this is done in a @RequestScoped
Bean. In my understanding the method retrieveAllMembersOrderedByName
is anyway called by each request. Should this @Observes
not be better placed in a @ViewScoped
or @SessionScoped
Bean? Does it have an effect in this case at all?