Java Reference
In-Depth Information
@Produces
@javax.enterprise.context.RequestScoped
public FacesContext produceFacesContext() {
return
FacesContext.getCurrentInstance();
}
}
As you can see, this class will be the factory for three kinds of resources:
EntityManager , which will resolve to the "primary" persistence unit
since there is just one persistence unit defined
java.util.Logger , which will trace some information on the server
console
FacesContext , which will be used to output some JSF messages on
the screen
Tip
Producers versus the Java EE 5 @Resource injection
If you have never used the dependency injections framework before, you might
wonder what the benefit is of adding an extra layer to produce some container
resources. The reason becomes evident once you need to change some con-
figuration elements, such as the persistence unit. With the older Java EE 5 ap-
proach, you will be forced to change the @Resource injection's details wherever
they are used; however, using a producer method for it will centralize resource
creation, making changes trivial.
Next we will add some entity producers; let's add the SeatTypeProducer and
SeatProducer classes:
@javax.enterprise.context.RequestScoped
Search WWH ::




Custom Search