Over a million developers have joined DZone.

Integrating Direct Ajax into the Enterprise Environment

DZone's Guide to

Integrating Direct Ajax into the Enterprise Environment

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

I'd like to introduce an Ajax framework which combines the ease of Direct Ajax with the benefit of the J2EE container, using JBoss SEAM. I've found the most appropriate name:

Distributed Ajax Application Model



Developing enterprise applications with a web-based user interface is not at all a trivial task, as everyone knows. If we tend to use standard Java solutions, our best choice might be Facelets with JBoss SEAM, however if we develop an enterprise application rather than a dynamic web page, we won't be quite satisfied. Or at least I was not. So I turned to the ITMill framework, which I knew earlier. This framework allows us to develop our user interface code totally Swing-like, and the framework is responsible of handling all HTML and HTTP related stuff. This solution evolved to what we nowadays call Direct Ajax. But I was still not satisfied, for I lost the ease of enterprise development SEAM gave me with Faces.

The idea

So I wanted to have injected EJB dependencies and a JPA session in my server-side user interface code. Normally Swing-like user interface code is not split into container managed beans, but that's actually far from impossible. Applications can usually be split into several functional groups which have little communication with each other, so why not put these into Seam components?

The solution

Decomposing a windowed application is done by introducing two special elements to the user interface model. A special type of Panel is used to be the actual SEAM component. This ContainerComponent is responsible of handling the rendering and event dispatching of the Controls it contains. On the other side a remote ContainerComponent can be added to a Control tree by a reference to that component. The ContainerComponentRef object is responsible of invoking the remote render method. These components do not access the Controls of each other.

To dispatch the events coming from the client-side user interface component, we need to know which component contains the server-side instance of the Control. To be able to do this, we use a composite Id of Controls which has the JNDI name of the container component and a number which is unique in itself for the application. The lifecycle of the components is handled by SEAM and the EJB container.

Direct Ajax is implemented mostly as seen in the ITMill framework. The client side UI code is written in GWT, so the framework can be extended with custom components quite easily. Finally, a simple servlet does the trick to initiate SEAM on each request, just as SeamListener does in Faces.

Some code

So what does it look like? Let's see a simple container:

public class ProductsPanel extends AbstractContainerComponent {

Label title = new Label("Products");

Table productTable = new Table();

EntityManager em;

public void init() {
new String [] { "Id", "Name", "Price", "-", "-" }));

And a listener might look like this:

public void buttonClicked(ButtonBase button) {

Current state

The framework currently is quite minimal. I'm going to go on extending it into a really useful UI framework, but I'd like to rely on community feedback and support. An example application project is available at http://hhc.intro.hu/daam/: it can be built to run on JBoss. The whole project will be available as soon as I get my sourceforge project approval and finish some documentation.

Finally, I wish you all a happy new year! :)


Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}