close

Filter

loading table of contents...

Workflow Manual / Version 2010

Table Of Contents

5.3.5 Access Workflow Variables from the Action

It is good practice not to hard code the variable names into the action bean, but to use configurable attributes to access the workflow variables. Thus, it is easier to reuse the action in other workflow definitions. Here is how you do this:

1: <Variable name="MyFirstVariable" type="String>
2:   <String value="OnlyATest"/>
3: </Variable>
4: <AutomatedTask name="One" successor="Two">
5:  <Action 
   class="com.customer.example.workflow.action.ParameterAction"
6:          variableToPass="MyFirstVariable"/>
7: </AutomatedTask>

Example 5.4. How to configure an action bean


In the example above, you defined a string variable with the name "MyFirstVariable" and the value "OnlyATest". With line 6 you configure the action bean that the method setVariableToPass() on an instance of com.customer.example.workflow.action.ParameterAction is called with the name of the string variable as a parameter.

1: public class ParameterAction extends AbstractAction {  
2:  private String text;
3:   ...  
4:  public String getVariableToPass() {return variableToPass; } 
5:  public void setVariableToPass(String t) {variableToPass = t;}
6:  public WfActionResult execute(WfTaskInstance wfTaskInstance) 
     throws WfException {
7:     ...
8:      WfAtomicVariable variable = 
           wfTaskInstance.getAtomicVariable(variableToPass));
9:     ...
10:  }   
11:} 

Example 5.5. Example of an action


Line 4 - 5: Here you define the setter and getter methods for the configuration of your action bean.

Line 8: Here you get the workflow variable using the name configured with the setVariableToPass() method.

Search Results

Table Of Contents