Rivet Logic Blogs

Tag: Seam

At Rivet Logic we do quite a bit of work with the JBoss Seam framework, specifically with our Content Management System integration we call Crafter rivet.

Seam can be used with the Spring bean factory framework, a popular “IoC” or Inversion of Control / Dependency injection framework. Spring enables developers to create instances of java objects known as beans and then to wire them to other java objects. Most people working in J2EE today are familiar with this so I won’t spend any time going in to further detail here. Seam also supports the ability to use java annotations to declare a class as a bean and to specify how it should be wired through what they call out-jection and injection. Check out the Seam website for more details on how the Seam bi-jection mechanics work.

One question that has come up for me many times on consulting engagements is: “which approach to use, Spring or Seam bi-jection?” My experience shows me that the answer is not one or the other. Both approaches have significant benefits and can be used together to create a stronger approach than either one can provide on its own.

Here are some very simple guidelines

When to use Spring beans:

Infrastructure components and services are great candidates for Spring beans

Such services are generally singletons within the system. Spring has excellent support for managing and wiring these objects

Such service classes are often packaged in separate more commonly used libraries. Hard coding a bean name and wiring within the class definition or strongly coupling to Seam is less desireable.

You want a very simple way to override the implementation at deployment time. Consider a scenario where you want to override a DAO. By managing the bean in Spring it is extremely easy to override the bean definition to use an alternate class and configuration in a given environment simply by placing an additional xml file in the classpath

When to use Seam annotations:

Domain specific components are good candidates for bi-jection.

They are often fine grained application specific components.

Explicitly stating how the component will be wired in the the class file has little impact on its re-usability because its scope is limited to the application at hand.

Such components really benefit from one of Seams strongest features in its bean framework: Conversation Scoping. This is the ability to define a life-cycle which is shorter than a session. By limiting the lifetime of a object to its true life-cycle it’s possible to free memory up for other needs within the system. On large, high troughput applications the benefits here cannot be overstated.

By using a combined approach you get the reusability and flexibility of Spring framework with the performance orientation of conversation scoping and ease of development associated with Seam annotations.

Since Alfresco was first released in 2005, I have led a number of projects that required some sort of custom user interface on top of the Alfresco repository. In a few cases, we customized Alfresco’s standard web client. For others, we built custom interfaces that were stand-alone web applications or were exposed via portlets within a portal framework like Liferay or JBoss Portal.

In most cases, we needed a user interface that was not embedded within the repository, but rather was hosted remotely as a standalone web application. To do this, the main choices for the web application to communicate remotely with Alfresco are the following mechanisms:

Each one of these approaches has its pros and cons and the choice is highly influenced by the client’s needs.

Alfresco’s Surf platform provides a powerful framework that enables developers to leverage most if not all of the repository’s features using a RESTful approach using their Web Script runtime engine. It also allows for the web tier to be remote to the Alfresco repository. Surf is a very good option for projects that have a Javascript-centric web tier, using frameworks such as ExtJS. We have successfully built and deployed several Web Script-based UIs for customers, including one of the very first public sites to leverage Web Scripts found at http://highschool.ccsso.org. In its most recent v3.0 release, Alfresco provides a UI platform for aggregating Surf dashlets to create fully functional web clients. This platform is known as Alfresco Share.

However, we also have customers who want a Java-based UI solution too. Alfresco’s original web client UI is a JSF/Spring based application that is customizable in many ways and is the only available alternative in this case (short of building your own web client). It is built using a large number of custom JSF components that are very nice as long as your target UI is expected to behave similarly to Alfresco’s web client. If you were asked to change the way one or more of these components work things start to get a little hairy especially when you realize how much work is required to make it do exactly what was needed. There was an apparent need for developing a Java-based UI platform that shared some of the Share features.

So we set out to fill this void: To create an open source, Java-based UI platform for Alfresco.

We turned to JSF for the view framework, as it is the predominant standard in the Java community. One of the challenges of JSF component development has always been ease of customization, or the lack of it. Even though the JSF spec allows for extending UI components, it is still not trivial to make your components very flexible. And what typically happens in those situations is that smart people decide to put in a lot of work into getting rid of the problem. That’s where the JSF component suites come in. There are a lot of them out there. Some open source, some not. Naturally I’m only interested in the open source ones.

When working with JSF components suites like JBoss RichFaces you gain a lot of leverage when you incorporate a framework that makes dealing with the JSF lifecycle both intuitive and easy. If you guessed that I was talking about JBoss Seam, you’re right.

Projects that are more Java-centric and make use of web frameworks such as JSF would find that a remote Java API that provides access to the Alfresco Foundation Services (AFS) is necessary. In this case, our own Remote Alfresco API rivet is ideal. It is both scalable and fits within the JEE tiered approach quite nicely.

For these reasons, the technology stack we used for building our Java-based Alfresco web client is comprised of JBoss Seam, RichFaces/Facelets, and RAAr.

So here was the perfect opportunity to bring all this technology together and provide the Alfresco community with an example of a new way for developing Web 2.0 rich web clients for the Alfresco repository. We decided that the web client had to be rich (AJAX is key here and RichFaces among other JSF component suites makes it possible), remote from the Alfresco repository, and modular so that it could be reused in other projects in the future. And while we were at it, it needed to be easy for new developers to contribute to.

We gave the web client a name that explains what it really is; Seam Client for Alfresco rivet — SCAr. (As an aside, because we incorporate RichFaces we also considered calling it ScarFaces :^)

From a high level, SCAr makes use of RAAr to utilize a complete suite of services that fully expose Alfresco ECM’s core services at the back-end, and a number of out of the box JBoss RichFaces AJAX enabled UI components at the front-end tied together using JBoss Seam to provide a single page multi-user interface to Alfresco ECM’s document management system. The following diagram shows a high-level overview of SCAr. The power of this architecture is in its inherent simplicity without sacrificing flexibility.

The internal architecture of SCAr is broken down into a number of RichFaces components each exposing one or more of Alfresco’s document management features. Each RichFaces component is backed by a Seam action class (POJO), where each Seam listener has access to a RAAr abstraction layer providing it with an easy to use domain specific API into Alfresco ECM. By making use of Seam observers each user action triggers one or more events at the back-end allowing one UI component to manipulate the state of the other components on the screen as needed.

The following is a screenshot of what SCAr looks like to a typical end user:

This development framework makes enabling new features and customizing the behavior of existing ones straightforward.