Welcome!

Java Authors: Maureen O'Gara, Bruce Armstrong, Liz McMillan, Walter H. Pinson, III, Yakov Werde

Related Topics: Java

Java: Article

Seam: The Next Step in the Evolution of Web Applications

A powerful new application framework for managing contextual components

The @BeginTask annotation takes the task associated with the taskId parameter and makes the corresponding process state available to the component. That allows the orderId to be injected and the corresponding order shipped. Since we've greatly simplified the flow here, this method uses the @EndTask annotation to signal the completion of the task.

If the operation succeeds, the process will advance. In this simple example, the process completes, but if the process were more complex, other tasks, possibly for other users, might be created. Those new tasks would see any changes to the process state.

We won't add any more tasks here. Instead let's make one tiny change to the process to illustrate how business process can further simplify the flow of the application. Let's imagine that we wanted to send an e-mail after shipping the order. We could do that in the ship() action, but then we'd be mixing the concerns of components. The ship component should only be concerned with the single action of shipping the order.

There are many ways to add actions to a process in jBPM. We'll associate the e-mail action with the transition out of the state.

<transition name="shipped" to="complete">
    <action expression="#{shippingEmail.send}" />
</transition>

This expression invokes the send action on the shippingEmail component. It's easy to see how a Seam component could inject state from the process, pull out the information to put in the e-mail, and use JavaMail to notify the user that the order has shipped.

Using a process lets us separate out process concerns like sending a notification from application concerns like marking an order as shipped in the database. Seam lets us integrate with the business process without coupling the code to business process APIs or complicating the components with complex state management. Seam simplifies the application by letting components focus only on the exact task they're meant for and delegating all glue code to Seam.

One More Thing...
There's a lot more to say about Seam. This article has focused entirely on the management of contextual components to provide for simpler Web application development. However, Seam goes well beyond that. Let's look at some of the other things that make Seam interesting.

The conversation model in Seam is much richer than what is shown here. Seam can carry on conversations with multiple components on a single page and switch between conversations. It has additional contexts beyond the ones mentioned so far. One example is the page context that stores state from one requrest for a subsequent request.

Seam provides for model-based entity validation. Most Web application require user input to be validated. Sometimes this is done on the client side and sometimes it's done on the server side, but it's almost always a function of the UI. Seam provides an additional layer of model validation. Instead of only being about to say that an input field has to contain a valid e-mail address, an entity could use the Hibernate validation annotations to express that the e-mail address of the person entity should be a valid e-mail address. Seam can apply these validations any time an entity is used in a form.

Seam supports the use of jBPM definition to describe the flow of pages in a conversation. jBPM pageflow is simpler and cleaner than JSF navigation, and allows for a separation of flows in an application. Pageflow definitions can be created and maintained using the visual process editor in jBPM.

Seam applications and application components can be automatically generated, so a Seam-based application can get up and running quickly. This includes the now-popular generation of CRUD applications from a database schema.

Testing is central to JBoss Seam. Seam supports testing user interactions with components in unit tests. These tests can be run, either in the IDE or from your build script, without involving an application server.

Finally, JBoss Seam supports non-EJB development. This article show EJB3 integration, but Seam also supports Hibernate persistence directly. Application logic can be written using plain JavaBeans instead of EJB3 session beans. Seam applications can run inside any application server or even in a bare Web container like Tomcat.

Conclusion
Seam is a powerful new application framework for managing contextual components. Seam represents the next logical step in the evolution of applications, letting Web application components take advantage of a much richer set of contexts without polluting the components with code unrelated to the core function of the component. Seam is fast and easy and represents the state-of-the-art of modern Web development.

Resource

More Stories By Norman Richards

Norman Richards is a JBoss developer living in Austin, Tx. He is co-author of JBoss: A Developer's Notebook and XDoclet in Action.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
SYS-CON Belgium News Desk 02/19/06 01:41:18 PM EST

Web sites were originally static. Later dynamic content came about through CGI scripts paving the way for the first true Web applications. Since HTTP was entirely stateless, it became necessary to invent ways for requests to be linked together in a sequence. At first state was added to the URLs, but later the cookie concept came into being. By giving each user a special token, the server could maintain a context for each user, the HTTP session where the application can store state. As simple as it is, the HTTP session defines the entire concept of what a Web application is today.