Steven Verborgh

Just another weblog

January 2010 Archives

Configuring a datasource for the embedded-glassfish maven plugin

Maven is can be a magnificent tool, that allows you to get real work done. Recently with the release of the embedded Glassfish API and a Maven plugin to control an embedded instance, rubyesque ./script/server workflow are no longer impossible for Java Developers. Being able to send colleague developers a project they can just run from maven, no setup involved is a great step forward.

There are several resources on the internet that explain how to add the plugin to you maven project. But only one mentions the use of a datasource in his project an even then the solution is an ugly hack that leads to places where developers cry behind the corner. In this small intro I'll you how to get started with one of the weld artifacts, because it provides a basic JPA project.

Continue Reading…

Posted by verborghs on Jan 29, 2010

Porting the ViewScoped JSF annotation to CDI

UPDATE: This implementation is something I created as a temporary solution untill JBoss releases the seam face module. You should try to get that one working instead. This article might help you gasp the inner workings a bit, but keep in mind this code is to simple to be reliable.

As you might know, JavaServer Faces 2 comes with some optional annotations. Optional, because halfway throught the specification process something called Dependency Injection for Java (JSR330) and something else called Context and Dependency Injection or CDI (JSR299) came to life. That means we have some very usefull annotations like @ViewScoped that are specified in the JSF 2 specification that have no alternatives in CDI.

CDI specifies @RequestScoped, @SessionScoped, @ApplicationScoped and @ConversationScoped because these scopes are somewhat technology independent. A scope like @ViewScoped is bound to a view technologie that has a concept of views. In the case of JSF this is a scope that remains into existence as long as we are using the page and doing postbacks to that page.

This is a very usefull scope. We can put objects in this scope by putting them into the the map that is associated to the UIViewRoot of a view. In this article we will look at how we can create a custom @ViewScoped annotation, a custom CDI Context and a Extension that will behave "like" the optional JSF @ViewScoped annotation.

Continue Reading…

Posted by verborghs on Jan 06, 2010