I’ve just started a small CDI integration with tapestry web framework: https://github.com/rmannibucau/cdi-tapestry-contribution
The idea is to be able to inject CDI beans as tapestry page fields.
To build it once you downloaded it, simply run the following command:
mvn clean install
Then you can add the maven dependency:
<dependency> <groupId>com.github.rmannibucau</groupId> <artifactId>cdi-tapestry-contribution</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency>
To use it once the dependency is added, simply inject your CDI beans as usual :
public class Index { @Inject private Pojo pojo; @Inject @Named("named") private NamedPojo namedPojo; public String getPojo() { return pojo.name(); } public String getNamedPojo() { return namedPojo.name(); } }
Note: in some case, you may need to add the cdi-tapestry module explicitely to your application module :
@SubModule({ CDIInjectModule.class }) public final class MyModule { [....] }
That’s all!
Sounds very interesting… If used with JTA and JPA, will the CDI beans run in the same transaction as the rest of the Tapestry application?
I’m not sure what you think of speaking of JTA/JPA in Tapestry so maybe i miss something but the module simply inject beans keeping all environment so it should be fine.