How to make @EJB Annotation work in Tapestry pages and components
This works on Tapestry 5.3 or higher. Has been tested with Glassfish 3.1.
Code excerpts are from Flow Logix Tapestry Library
In your AppModule.java file, add the following method
@Contribute(ComponentClassTransformWorker2.class) @Primary public static void provideClassTransformWorkers(OrderedConfiguration<ComponentClassTransformWorker2> configuration) { configuration.addInstance("EJB", EJBAnnotationWorker.class, "before:Property"); }
EJBAnnotationWorker.java
(add this to one of your non-tapestry packages)
Using Stateless @EJB in your client code
class SomeTapestryPage { private @EJB MyStatelessBeanLocal localBean; }
Using Stateful Session Beans in your client code
class SomeTapestryPage { private @EJB @Stateful MyStatefulBeanLocal statefulBean; // stored as SessionState object private @EJB @Stateful(isSessionAttribute = true) MyStatefulBeanLocal statefulBean2; // stored as SessionAttribute object }