Java Reference
In-Depth Information
@EJB
private AcmeTimerFacade timerFacade;
@Inject
ServletContext context;
...
public String getContextInfo(){
return context.getServerInfo();
}
}
Now within a JSF view, the server information can be displayed by simply calling upon the contextInfo getter
that was implemented in AcmeBean .
<h:outputText id="widget" style="font-weight: bold;" value="#{acmeBean.contextInfo}"/>
Marking Classes as Ignored by CDI
Almost any Java object can be injected using CDI, and injection is even possible into beans that are not managed by
CDI. A managed bean in the context of CDI is a bean class that is implemented by a Java class. CDI utilization within
managed beans serves a number of purposes. For instance, managed beans can be annotated for scoping, naming
and referential purposes, and so forth. EJB session beans can also utilize CDI in a number of ways, similar to managed
beans. The topic of CDI usage within managed beans and session beans is very large and out of scope for this topic
on new features. Therefore, to learn more about the ways CDI can be used in these bean types, please refer to the
documentation or other topics, such as Java EE 7 Recipes by Apress.
New to managed and session beans in CDI 1.1 is the ability to veto beans in a declarative manner by utilizing the
@Veto and @Requires annotations. To veto a bean means to mark it as ignored by CDI. Therefore, if a bean contains
the @Veto annotation, it cannot be processed by CDI. A vetoed class will not contain the life cycle of a contextual
instance, nor can it be injected into other classes. In fact, if a managed bean or session bean contains the @Veto
annotation, it cannot be considered a managed bean or session bean at all. In some cases, it makes sense to mark
a bean as such to ensure that it cannot become managed by CDI. The following code demonstrates how to apply the
@Veto annotation to a class:
@Veto
public class OrderFacade implements java.io.Serializable {
...
The @Veto annotation can also be placed on a package declaration, which will prevent all of the beans that are
contained within that package from being processed via CDI.
@Veto
package org.javaee.chapter7.*;
...
Any of the following definitions on a vetoed type will not be processed:
Managed beans, session beans, interceptors, decorators
Observer methods, producer methods, producer fields
 
Search WWH ::




Custom Search