WorkflowExplained

The workflow explained

This workflow engine takes a little different approach like other frameworks. At least other frameworks tha we know about.
Every process item inside a workflow can set variables and these variables can be used by other items in order to communicate.
Most other framework lets you define a return value of your action and then you define a forward depending on the return value. This is not really sufficient for a good inter process communication where different items needs to share common informations.

First example

These variables can be set by views or commands and can be used by all items. Setting a variable can be done like this:
import org.jzonic.core.AbstractCommand;
import org.jzonic.core.CommandException;
import org.jzonic.core.WebContext;

public class ExampleCommand extends AbstractCommand {
    
    public ExampleCommand() {
    }
    
    public String execute(WebContext context) throws CommandException {
        String val = context.getRequestParameter("value");
        context.setVariable("varname", val);       
        return null;
    }
    
}

This will add the variable called "varname" with the value from the request parameter "value".

Using this variable inside an if/else block is here:
<page name="redirect">
  <command>ExampleCommand</command>
  <if expression="${varname}='hello'">
    <view>WelcomeView</view>
  </if>
  <else>
    <redirect>index.jz</redirect>
  </else>
</page>


Second example - Using a variable inside a process item definition

You can also use this to "skin" your applications by using a different jsp depending on such a variable:
import org.jzonic.core.AbstractCommand;
import org.jzonic.core.CommandException;
import org.jzonic.core.WebContext;

public class SkinExampleCommand extends AbstractCommand {
    
    public SkinExampleCommand() {
    }
    
    public String execute(WebContext context) throws CommandException {
        // just get the info from an imaginary configuration
        String val = config.getProperty("skin");
        context.setVariable("theme", val);       
        return null;
    }    
}

and now put it in a page:
<page name="main">
  <command>SkinExampleCommand</command>
  <jsp>${theme}/hello.jsp</jsp>
</page>

When you use a variable inside a process item you have to put it in ${varname}. This example will take the JSP from the corresponding subdirectory of your webapps directory.


revision: 4 / last update: 25.08.2004 10:46:36