ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

JBoss Seam
Pages: 1, 2, 3, 4, 5

In the following example for the DVD store application, we add business process to the validation of any order. Let's add a business process that automatically accepts every order under 100 dollars and delegates validation to an administrator for all other orders. Once the validation is made, a process step is needed to add the shipping number information. To do such a process, we decided to write the following JPDL:

<process-definition name="OrderManagement">
        <transition to="decide"/>
    <decision name="decide" 
        <transition name="large order" 
        <transition name="small order" 

    <task-node name="approval">
        <task name="approve">
             pooled-actors="reviewers" />
        <transition name="approve" 
        <transition name="reject"  
    <task-node name="process">
        <task name="ship">
           <assignment pooled-actors=
        <transition name="shipped" 
            <action expression=
    <end-state name="complete"/>

In this simple but yet powerful example, we see how the integration of jBPM and Seam let you directly enter JSF expressions directly into the jPDL. The #{orderApproval.howLargeIsOrder} calls the howLargeIsOrder method on the "orderApproval" Seam component, which is exactly how it works in the JSF page. Here is the source code for that Seam component:

package com.jboss.dvd.seam;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

public class OrderApprovalDecision {
   @In float amount;
   public String getHowLargeIsOrder()
      return amount > 100 ? 
        "large order" : "small order";

Nothing fancy here; we just injected the amount from the stateful contexts and a string returns indicating which decision to take. We can also notice in the pageflow definition that the transition from "process" to "complete" triggers a call to the "log" method of the "afterShipping" Seam component.

Portable and Lightweight

Seam relies exclusively on JDK 5.0 annotation metadata for the declaration of components and how they are associated in a particular context--no XML hell. Seam can be used with any JSF implementation and runs on any JEE 5.0 container. With the Microcontainer, Seam can even be used in Tomcat or in unit tests. For developers who are not ready yet for EJB 3.0, Seam also supports POJOs and Hibernate persistent classes as components.

The DVD store example can work in Tomcat by adding few configuration files; there is such an example in the Seam distribution.


Thomas Heute is the project leader of JBoss Seam

Return to ONJava.com.