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

advertisement

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">
    <start-state>
        <transition to="decide"/>
    </start-state>
    
    <decision name="decide" 
expression="#{orderApproval.howLargeIsOrder}">
        <transition name="large order" 
                       to="approval"/>
        <transition name="small order" 
                       to="process"/>
    </decision>

    <task-node name="approval">
        <task name="approve">
           <assignment 
             pooled-actors="reviewers" />
        </task>
        <transition name="approve" 
                       to="process"/>
        <transition name="reject"  
                       to="complete"/>
    </task-node>
    
    <task-node name="process">
        <task name="ship">
           <assignment pooled-actors=
           "#{shipperAssignment.pooledActors}"/>
        </task>
        <transition name="shipped" 
                       to="complete">
            <action expression=
                   "#{afterShipping.log}"/>
        </transition>
    </task-node>
    
    <end-state name="complete"/>
</process-definition>

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;

@Name("orderApproval")
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.

Resources

Thomas Heute is the project leader of JBoss Seam


Return to ONJava.com.