Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Use Dojo TreeGrid to manage WebSphere Process Server workflow

Create a Web 2.0-style UI for your data

Wang Qiang (wangqsh@cn.ibm.com), Software Engineer, IBM
Wang Qiang photo
Wang Qiang is a software engineer on the IBM ORIA team at the IBM China Development Lab in Shanghai. He is currently focusing on Dojo Grid development and Dojo TreeGrid enhancement.
He Gu Yi (heguyi@cn.ibm.com), Software Engineer, IBM
Photo of He Gu Yi
He Gu Yi, a software engineer at the IBM China Development Lab in Shanghai, is working on Web 2.0-related projects. His expertise includes Ajax and the Dojo library.
Ruan Qi (rqruanqi@cn.ibm.com), Software Engineer, IBM
Ruan Qi photo
Ruan Qi is a software engineer at the IBM China Development Lab in Shanghai. He works on the IBM ORIA team. Ruan's expertise includes web visualization development.

Summary:  IBM WebSphere® Process Server is a powerful business process management platform. Its built-in process management tool, Business Process Choreographer‎, supports multiprocess management. With Web 2.0 booming, though, users want to customize the management user interface to support Ajax features. TreeGrid, a Dojo widget, has the ability to display and manage multidimensional, complex data structures. With TreeGrid you can also create compelling, interactive user interfaces. In this article, learn how to manage the processes in WebSphere Process Server with Dojo TreeGrid and provide an attractive user experience.

Date:  11 Jan 2011
Level:  Introductory PDF:  A4 and Letter (504KB | 18 pages)Get Adobe® Reader®
Also available in:   Chinese  Japanese

Activity:  10012 views
Comments:  

Introduction

If you use IBM WebSphere Process Server then you already know about its many features. In this article, learn how to harness the power of the Dojo TreeWidget to manage your processes in WebSphere Process Server. Through an example, explore how to manipulate hierarchical data structures and create a Web 2.0-style user interface (UI) to manage your data.

You can download the sample code used in this article from the Download table below.


Dojo TreeGrid

The dojox.Grid, an important component of the Dojo widget, lets you easily operate and present remote data and data from web pages. TreeGrid has advantages of both dijit.Tree and dojox.Grid: It has tree's ability to handle the hierarchical data structures and grid's data presentation capabilities. Just like the dojox.Grid, there are two approaches to building a TreeGrid: declaratively or programmatically. Figure 1 shows a simple TreeGrid.


Figure 1. Simple Dojo TreeGrid
A                     simple Dojo TreeGrid, with the following headings: Player, Session,                     Game, Quarter, Points, Rebounds, Assists, and Time Played.

Architecture

TreeGrid adopted a Model-View-Controller (MVC) design pattern, as shown below.


Figure 2. Architecture of TreeGrid
Diagram showing the                     architecture of the TreeGrid, including a Model and a View.

TreeGrid maintains a data model to manage the original data that will be used by TreeGrid to present the data with a great UI. TreeGrid can access the data store to fetch or handle the data via the APIs provided by the dojo.data.api, which is the standard way to access the data in Dojo. Dojo provides lots of data stores that have implemented APIs of the dojo.data.api, including: ItemFileReadStore and ItemFileWriteStore (users can read or handle the JSON data using them); XmlStore, CsvStore, and OpmlStore for the other data formats; and so on. Table 1 summarizes the data stores.


Table 1. Implemented Dojo DataStores
DataStorePurpose
dojo.data.ItemFileReadStore Read-only data store for JSON data
dojo.data.ItemFileWriteStore Read/Write data store for JSON data
dojox.data.CsvStore Read-only data store for CVS data
dojox.data.OpmlStore Read-only data store for Outline Processor Markup Language (OPML) data
dojox.data.HtmlTableStore Read-only data store for HTML table data
dojox.data.XmlStore Read/Write data store for XML data
dojox.data.FlickrStore Read-only data store for queried data of flickr.com. An excellent example of a web service data store.
dojox.data.FlickrRestStore Advanced version of the dojox.data.FlickrStore
dojox.data.QueryReadStore Read-only data store for JSON data from the server side
dojox.data.AtomReadStore Read-only data store for the Atom XML data

The view is for retrieving and presenting the application data to the user properly. You can customize the view of TreeGrid by defining the structure parameter. There are two different kinds of TreeGrid views. The columnar TreeGrid has a layout more like a typical tree style, as shown in Figure 3. This view is created when you specify a TreeModel to the TreeGrid.


Figure 3. Columnar TreeGrid
A TreeGrid showing                     columns of data, with the following headings: Name, Population, and Time                     zone

The other TreeGrid view is a nested TreeGrid, which is defined by a nested structure, as shown below.


Figure 4. Nested TreeGrid
A TreeGrid showing                     nested data, with the same headings as Figure 1.

The controller handles and responds to events. The TreeGrid inherits from dojo.grid.DataGrid, so all event handlers pertaining to the DataGrid apply here. You can also customize your own event handler by binding the function to the grid events, thereby controlling the data and behaviors more effectively.

Usage

TreeGrid can be defined either declaratively in HTML or programmatically. Most properties of TreeGrid are optional except for structure and store (or treeModel if you need to create a columnar TreeGrid). Structure is a JSON object that defines the TreeGrid view layout. It can also be indicated by markup when the TreeGrid is defined declaratively in HTML. The value of store should be the name of a JavaScript variable that holds the store object used to get data for TreeGrid. Listing 1 shows a definition of a TreeGrid that's defined declaratively.


Listing 1. Sample TreeGrid definition
<table dojoType="dojox.grid.TreeGrid" store="storeId">
  <thead>
    <tr>
      <th field="field1" width="200px">Field 1</th>
      <th field="childAttr">
        <table>
          <thead>
            <tr>
              <th field="cField1" width="200px">Child Field 1</th>
              <th field="cField2" width="200px">Child Field 2</th>
            </tr>
          </thead>
        </table>
      </th>
    </tr>
  </thead>
</table>


Build the process server proxy

WebSphere Process Server provides various programming interfaces, such as EJB, Web Service, JMS, and REST, for you to manage the processes. However, only EJB APIs provide the complete function set. To leverage the power of the EJB API, you need to build a proxy that connects TreeGrid to the process server.

Set up the sample process application

The first step is to create a sample integration solution named SimpleSolution, which contains only one module. To simplify the example, we built a process with one receive/reply and a human task. The human task does nothing but enter an arbitrary string value as the return value of the reply action. Figure 5 shows the definition of the process. Remember, you can download the sample code used in this article from the Download table below.


Figure 5. Process definition
Image of the process                     definition with sections for Interface and Operations

Manage processes with the process server API

It is assumed that the IDE you're using is WebSphere Integration Developer, and that the proxy application is running on the process server. (Or, you need to install the process server client on your server.) The example first creates a dynamic web project. You'll see that the required process server libraries are referenced automatically.


Figure 6. SimpleBridge dynamic web project
Directory structure                     of the SimpleBridge

Process server provides a rich set of APIs to manipulate the processes. You need to locate the EJB service to access these APIs. Listing 2 shows how to access the business flow manager service.


Listing 2. Access business flow manager service
// Obtain the default initial JNDI context
InitialContext initialContext = new InitialContext();
// Lookup the remote home interface of the BusinessFlowManager bean
Object result = initialContext.lookup("com/ibm/bpe/api/BusinessFlowManagerHome");
// Convert the lookup result to the proper type
BusinessFlowManagerHome processHome =
   (BusinessFlowManagerHome) javax.rmi.PortableRemoteObject.narrow(result,
       BusinessFlowManagerHome.class);
BusinessFlowManager processManager = processHome.create();

Once you get the instance of BusinessWorkflowManager, you have the power to create, work on, and complete the processes. You can use the code in Listing 3 to access the process template.


Listing 3. Access the process template
ProcessTemplateData[] processTemplates = 
  processManager.queryProcessTemplates(null, null, 0, null);
for(int i = 0; i < processTemplates.length; i++){
  //Do something to the process template
}

Use the code in Listing 4 to create a process instance with a process template and to specify a value for the initial input parameter.


Listing 4. Create a process instance
ProcessTemplateData template = processManager.getProcessTemplate(templateName);
if(template != null){
  // create a message for the single starting receive activity
  ClientObjectWrapper input = processManager.createMessage(template.getID(),
     template.getInputMessageTypeName());
  DataObject myMessage = null;
  if (input.getObject() != null && input.getObject() instanceof DataObject) {
    myMessage = (DataObject) input.getObject();
    // set the strings in the message, for example, a parameter named “input”
    myMessage.setString("input", initialString);
  }
  // start the process
  PIID piid = processManager.initiate(template.getName(), instanceName, input);
}

Once the above steps are complete, go to http://localhost:9080/bpc and click Started By Me. You can see that the instance you just created is there, as shown below.


Figure 7. Sample process instance
Screen shot of the                     'Process Instances Started By Me' screen, showing the SimpleProcess in                     the list.

Go to My To-dos, and you'll see that there's a human task ready for you to deal with, as shown in Figure 8. This is the human task defined in the process definition.


Figure 8. Human task to be handled
Screen shot of the                     'My To-dos' screen, showing the SimpleTask ready for you to work on

Before you can deal with the human task you need to find it. You can use the query method of the process manager to get the task you want, as shown in Listing 5.


Listing 5. Get the To-do tasks
QueryResultSet result = processManager.query(
    "ACTIVITY.AIID, TASK.NAME", 
    "ACTIVITY.STATE = ACTIVITY.STATE.STATE_READY AND " +
    "ACTIVITY.KIND = ACTIVITY.KIND.KIND_STAFF AND " +
    "WORK_ITEM.REASON = WORK_ITEM.REASON.REASON_POTENTIAL_OWNER AND " +
    "PROCESS_INSTANCE.NAME = '" + entity.getAttributeValue("NAME") + "'",
    (String)null, (Integer)null, (TimeZone)null); 
for(int k = 0; k < result.size(); k++){
  // Get the AIID and the name of the task
  result.next();
  out.print("{id:'" + result.getOID(1) + "',");
  out.print("label:'" + result.getString(2) + "'}");
}

To work with the task you first have to claim it. Only by claiming it can you get the value of the input parameter and complete the task. Listing 6 shows how to claim a task and get the value of the input parameter.


Listing 6. Claim a task and get the value of the input parameter
ClientObjectWrapper input = processManager.claim(aiid);
DataObject activityInput = null;
if (input.getObject() != null && input.getObject() instanceof DataObject) {
  activityInput = (DataObject) input.getObject();
  String inputStr = activityInput.getString("input");
}
processManager.cancelClaim(aiid);

At this point you can finally work on the task and complete it. Listing 7 shows an example.


Listing 7. Work on the tasks
ActivityInstanceData activity = processManager.getActivityInstance(aiid);
ClientObjectWrapper output = processManager.createMessage(aiid,
   activity.getOutputMessageTypeName());
DataObject myMessage = null ;
if(output.getObject() != null && output.getObject() instanceof DataObject) {
  myMessage = (DataObject) output.getObject();
  // set the parts in your message, for example, an order number
  myMessage.setString("output", msg);
}
//complete the activity
processManager.complete(aiid, output);
Define the data exchange format

JSON is definitely the preferred data exchange format. You need to return the data as a JSON object tree so that TreeGrid can receive it. The structure is fairly straightforward. Template is the parent node of the process instances associated with the template; the to-do tasks are the children of the process instances.


Listing 8. Data format
{
  identifier: "id",
  label: "label",
  items: [{
    id: "1",
    label: "Template 1",
    instances: [{
      id: "2",
      label: "Instance 1",
      tasks: [{
        id: "3",
        label: "ToDo 1",
      },
      {
        id: "4",
        label: "ToDo 2",
      }]
    }]
  }
}


Manage the processes with Dojo TreeGrid

Once you set up WebSphere Process Server, a TreeGrid can be created to receive and present the process data provided by the process server. Some controls can also be added to TreeGrid to manage those processes.

Connect to the process proxy

As mentioned previously, the store attribute in the <table> tag (see Listing 1) indicates which DataStore you want to use to obtain the data. Since you need to connect to the process proxy, let's go through an example with dojox.data.JsonRestStore. JsonRestStore is a Dojo data store interface to JSON HTTP/REST web storage services that support read and write through GET, PUT, POST, and DELETE. JsonRestStore could also be defined in the HTML markup, as shown in Listing 9.


Listing 9. JsonRestStore declaration
<span dojoType="dojox.data.JsonRestStore"
    jsId="jsonStore" target="SimpleSolution/ShowAll/">
</span>

The target attribute indicates the target URL for the server-side data source. It assumes you're in the same domain, so the value of target would be a relative path. jsId is the identifier of this store.

Create the TreeGrid

In this example, TreeGrid is defined declaratively in the HTML with a <table> tag. The nested <th> tags define the columns in the table. Listing 10 shows the declaration of TreeGrid. The structure corresponds to the data format above.


Listing 10. TreeGrid declaration
<table dojoType="dojox.grid.TreeGrid" class="grid" autoHeight="true" jsId="grid"
    store="jsonStore" rowSelector="true" defaultOpen=true>
  <thead>
    <tr>
      <th field="label" width="20em" formatter="processSummary">Process Template</th>
      <th field="instances" aggregate="sum">
        <table>
          <thead>
            <tr>
              <th field="label" width="20em" formatter="instanceSummary">Instance</th>
              <th field="tasks" aggregate="sum">
                <table>
                  <thead>
                    <tr>
                      <th field="label" width="25em" formatter="taskSummary">Tasks</th>
                      <th field="status" width="20em">Status</th>
                    </tr>
                  </thead>
                </table>
               </th>
             </tr>
           </thead>
         </table>
      </tr>
  </thead>
</table>

At this point you should get the TreeGrid shown below.


Figure 9. TreeGrid presenting process data
 A TreeGrid with                     the following headings: Process Template, Instance, Tasks,                     Description, and Status.

It's quite simple, but the job is only half done. The next step is to add some controls in TreeGrid so it can communicate with WebSphere Process Server and manage the processes.

Communicate with WebSphere Process Server

In this section you'll add some controls in TreeGrid. Since Dojo 1.4, a widget can be added in the grid cell by a formatter (a JavaScript function with return values shown in the grid cell). The formatter can also help to format the summary cells in TreeGrid.

As shown in Listing 11, two kinds of widgets are going to be added to TreeGrid by the formatters:

  • dijit.form.ComboBox, for changing the task status
  • dijit.form.Button, for submitting the request

Listing 11. Controller formatters
// create an object to save all these ComboBox
var comboObj = {};
var fmtStatus = function(value, idx, treepath){
  // summary:
  //    format the cell to a comboBox Widget
  // value: string
  //    the attribute value of this cell
  // idx: integer
  //    row index, it would be negative if the cell is header cell or summary cell
  if(idx >= 0) {
    // get the identifier
    var id = jsonStore.getIdentity(grid.getItem(treepath));
    comboObj[id] = new dijit.form.ComboBox({
      store: comboStore, 
      searchAttr:"status"
    });
    comboObj[id].setValue(value);
    return comboObj[id];
  }else{
    // for summary cell
    return "";
  }
}
		
var fmtSubmit = function(value, idx){
  if(idx >= 0){
    return new dijit.form.Button({
      label: "submit", 
      onClick: dojo.hitch(null, "submit", value)});
  }else{
    return "";
  }
}

You need to add the formatters to the columns of the TreeGrid, as shown below.


Listing 12. Add formatter to the column
<th field="status" width="20em" formatter=” fmtStatus”>Status</th>
<th field="id" width="20em" formatter=” fmtSubmit”>Action</th>

Now the TreeGrid should look like Figure 10.


Figure 10. TreeGrid with controller
A TreeGrid with the                     following headings: Process Template, Instance, Tasks, Description,                     Status, and Submit

The Dojo Ajax IO functions, dojo.xhr*, can be introduced for communication with WebSphere Process Server. An XHR request is sent to the server to submit the new status once the Submit button is clicked. The grid would be refreshed to reflect the processes correctly after receiving the response of the server, as shown in Listing 13.


Listing 13. Communicate with WebSphere Process Server
var submit = function(id){	
  var status = comboObj[id].getValue();
    dojo.xhrPost({
      url: "SimpleSolution/" + status + "/" + id,
      load: function(data){
        if(data === "successful"){
          grid.update();
        }else{
          console.warn("operation failed:", data);
        }
      },
      error: function(error){
        console.err(error);
      }
  });
}

Now, each time you click Submit an XHR request is sent to WebSphere Process Server. You'll know if the operation is successful from the service response.


Summary

In this article you learned how to use Dojo TreeGrid to manipulate the processes of WebSphere Process Server. TreeGrid inherently can handle hierarchical data structures. You can have a Web 2.0-style UI to operate on the data easily by customizing TreeGrid for your specific application needs.



Download

DescriptionNameSizeDownload method
Sample code for this articlecode.zip26KBHTTP

Information about download methods


Resources

Learn

Get products and technologies

Discuss

About the authors

Wang Qiang photo

Wang Qiang is a software engineer on the IBM ORIA team at the IBM China Development Lab in Shanghai. He is currently focusing on Dojo Grid development and Dojo TreeGrid enhancement.

Photo of He Gu Yi

He Gu Yi, a software engineer at the IBM China Development Lab in Shanghai, is working on Web 2.0-related projects. His expertise includes Ajax and the Dojo library.

Ruan Qi photo

Ruan Qi is a software engineer at the IBM China Development Lab in Shanghai. He works on the IBM ORIA team. Ruan's expertise includes web visualization development.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere, Web development
ArticleID=607374
ArticleTitle=Use Dojo TreeGrid to manage WebSphere Process Server workflow
publish-date=01112011
author1-email=wangqsh@cn.ibm.com
author1-email-cc=bwetmore@us.ibm.com
author2-email=heguyi@cn.ibm.com
author2-email-cc=bwetmore@us.ibm.com
author3-email=rqruanqi@cn.ibm.com
author3-email-cc=bwetmore@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.

Special offers