Java Reference
In-Depth Information
Earlier, we mentioned that a preconfigured logger should be injected to a bean if it re-
quests it. We will create a simple logger producer that will use the information about the
injection point (the bean that requests a logger) to configure an instance:
package com.packtpub.wflydevelopment.chapter4.util;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import org.jboss.logging.Logger;
public class LoggerProducer {
@Produces
public Logger produceLogger(InjectionPoint
injectionPoint) {
return
Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}
}
We also allowed the injection of FacesContext instead of using the standard
FacesContext.getCurrentInstance() static method. This context is used, for
example, to display the stated error messages:
package com.packtpub.wflydevelopment.chapter4.util;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.faces.context.FacesContext;
public class FacesContextProducer {
@Produces
@RequestScoped
public FacesContext produceFacesContext() {
return FacesContext.getCurrentInstance();
}
}
Search WWH ::




Custom Search