Steven Verborgh

Just another weblog

Using The Glassfish EJBContainer in Netbeans.

Aug 05, 2010

As many already know, one of the features of Java EE 6 is the javax.ejb.embeddable packages that allows you to create an embedded EJB container through EJBContainer.createEJBContainer(). This is a useful feature when you want to write a unit test for your EJB's.

Sometimes you want a little bit more control over what is configured in the embedded EJBContainer. In this entry we will look at how we can specify a custom domain.xml to use with glassfish v3 implementation of this embedded container.

Supporting jquery ClientBehavior in JSF 2.0

Feb 12, 2010

In JavaServer Faces 2.0 they have attempted to integrate Ajax and javascript. In an attempt to make it as easy as possible, and to increase the pluggability of the entire framework, the decision was made to come up with the concept of ClientBehavior. This seems to have been inspired by the presence of f:validator and f:convertor. Non Gui components that add extra functionality to their parent tags.

In theorie this is ok, but the events to which you can attache behaviour, are limited to the events returned by the getEventNames() method of ClientBehaviourHolder. This interface is implemented by some components. For some reason the Specification team decided that in the HTML renderkit only the editable value holder should implement this interface, and that the only events that are supported are the official dom events. The last part I can understand since the HTML renderkit does only try to specify the minimum requirements.

In an attempt at integrating f:ajax for custom jquery events I ran into the limitations this imposes in relation to the front end development. We all know ASP.NET uses jquery, and it is a toolkit that is impossible to overlook at the moment. In this small howto we will write a jquery uicomponent that allwos us to attach f:ajax behaviour to it so we can invoke remote methods from backingbeans. The end result will look like this:

<h:form id="form">
    <h:panelGroup layout="block" id="draggable">
        <div><h:outputText value="Drag me"/></div>
        <howest:jquery events="dragstart,drag,dragstop" default="dragstop" plugin="draggable" options="{handle: 'div'}">
            <f:ajax listener="#{sample.doStart}" render="status" event="dragstart"/>
            <f:ajax listener="#{sample.doDrag}" render="status" event="drag"/>
            <f:ajax listener="#{sample.doStop}" render="status" event="dragstop"/>
        </howest:jquery>
    </h:panelGroup>

    <h:outputText id="status" value="#{sample.status}" />
</h:form>

We will be using ResourceDepency to inject the correct jquery libraries. The tag as you can see will allow us to create composite tags that use jquery. For example a draggable tag or whatever you want.

You can get the code from github here. It's a slightly modified maven library and demo project that should get you up and running.

Configuring a datasource for the embedded-glassfish maven plugin

Jan 29, 2010

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.

Porting the ViewScoped JSF annotation to CDI

Jan 06, 2010

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.

Arrrrcamp "unpresentation"

Nov 28, 2009

You don't go to a Barcamp and just sit there! You get out an talk, and my present something if you feel like ... or as in my case "unpresent" something. Keep in mind, I had no preparation whatsoever except the rum they handed out for free. But hey, I don't think pirates rehearsed or something, so why would I. Arrrrr(gh).

ruby extensions from Openminds on Vimeo.