Tapestry with CDI beans?


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!

Advertisements

2 thoughts on “Tapestry with CDI beans?

  1. Ronald van Kuijk

    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?

    Reply
    1. rmannibucau Post author

      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.

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s