EJB 3.1 Killed The Backing Beans Or JSF 2, EJB 3.1, JSR-330 - The Perfect Synergy 📎
A Stateless Session Bean with the JSR-330 @Named annotation:
@Stateless
@Named("helloService")
public class HelloService {
@EJB ClockService clockService;
public String getHello(){
return "Hello from EJB / CDI: " + clockService.currentTime();
}
}
can be directly referenced in the JSF 2:
<h:body>
<h:form>
<h:outputLabel value="#{helloService.hello}"/>
</h:form>
</h:body>
You don't need the Backing Bean anymore - but you can still use it.
The project (JSF2EJB3CDI) was implemented in few minutes with NetBeans 6.8, tested with Glassfish v3 and pushed into: http://kenai.com/projects/javaee-patterns/. The entire WAR (JSF 2.0 , EJB 3.1, CDI) is 8 kB small. The initial deployment took 1.516 ms seconds, and was twice as slow, as in the Java EE 6 observer example:
INFO: Initializing Mojarra 2.0.2 (FCS b10) for context '/JSF2EJB3CDI'
INFO: Loading application JSF2EJB3CDI at /JSF2EJB3CDI
INFO: JSF2EJB3CDI was successfully deployed in 1,516 milliseconds.