9 Replies Latest reply on May 12, 2006 7:30 PM by sarva

    ActionHandler configuration

    sarva

      If I have a actionhandler like this,


      public class MyAction implements ActionHandler {
       // access specifiers can be private, default, protected or public
       private String city;
       Integer rounds;
       ...
      }
      


      I want instantiate the city property with a context variable like the following,

      ...
      <action class="org.test.MyAction">
       <city>#{city_param}</city>
       <rounds>5</rounds>
      </action>
      ...
      


      This one does not work. I'm looking for other ways to do the same.
      Please help.

      Thanks,


        • 1. Re: ActionHandler configuration
          jemodurn

          You can try to add a getter/setter for your private variables and use the config-type="bean" in the action definition.

          • 2. Re: ActionHandler configuration
            sarva

            Even if I have something like,

            public class MyActon implements ActionHandler {
            
             String city;
            
             public String getCity() {
             return city;
             }
            
             public void setCity(String _city) {
             city = _city;
             }
            }


            How do I pass in the context variable city_param with either config-type field or bean?


            • 3. Re: ActionHandler configuration
              hosierdm

              If you always want to pass in the variable as the value to the action handler, you don't even need to specify it in the configuration. You can access your process variables from the ExecutionContext

              city = executionContext.getVariable("city_param");


              • 4. Re: ActionHandler configuration
                jemodurn

                If the variable is in the context, you can access it in your action handler.


                public void execute(ExecutionContext context) throws Exception {
                 context.getContextInstance().setVariable("message", message);
                 city_param = (String) context.getContextInstance().getVariable("city_param");
                }
                


                • 5. Re: ActionHandler configuration
                  sarva

                  This is exactly what I want to avoid. In this case the action handler is dependent on the specific city_param context variable. This prevents me from using the same action handler in another step where I want to use a different context variable/constant for the city property.

                  • 6. Re: ActionHandler configuration
                    eruiz

                    You can use OGNL:

                    import ognl.Ognl;
                    
                    public class MyActon implements ActionHandler {
                    
                     String cityExpression;
                    
                     public String getCity() {
                     return cityExpression;
                     }
                     public void setCity(String _city) {
                     cityExpression = _city;
                     }
                     public void execute(ExecutionContext eContext) throws Exception {
                     Object cityValue = Ognl.getValue(cutExpression(cityExpression), getVariables(eContext));
                     }
                     protected String cutExpression(String str) {
                     // return the expression without the prefix #{ and without the suffix }
                     }
                     protected Map getVariables(ExecutionContext eContext) {
                     Map vars = eContext.getContextInstance().getVariables();
                     Map tVars = eContext.getContextInstance().getTransientVariables();
                     Map context = new HashMap();
                     context.putAll(vars);
                     context.putAll(tVars);
                     return context;
                     }
                    }
                    


                    This approach can be generalized a little more :D

                    You can learn more about OGNL at http://www.ognl.org/2.6.7/Documentation/




                    • 7. Re: ActionHandler configuration
                      hosierdm

                      This thread http://jboss.org/index.html?module=bb&op=viewtopic&t=82061 seems to indicate that what you want to do is not possible in the current incarnation of jbpm. See Tom's response in this thread. Does that match up with what you were trying to do?

                      • 8. Re: ActionHandler configuration
                        koen.aers

                        The feature you need *is* supported in the current incarnation of jBPM.. From the websale example:

                        <node name="ship item">
                         <action class="org.jbpm.websale.ShipItem">
                         <swimlaneName>shipper</swimlaneName>
                         <msg>${shipper} now ships ${item} to ${address}</msg>
                         </action>
                         <transition to="salejoin" />
                         </node>
                        


                        Regards,
                        Koen

                        • 9. Re: ActionHandler configuration
                          sarva

                          Thanks for all your help.

                          The shipitem example is a hack as can be seen from the code of the action handler where it still uses the context variables by name,

                           String displayMsg = replace(msg, "${"+swimlaneName+"}", actorId);
                           displayMsg = replace(displayMsg, "${item}", (String)contextInstance.getVariable("item"));
                           displayMsg = replace(displayMsg, "${address}", (String)contextInstance.getVariable("address"));
                          


                          The OGNL approach is more elegant. That should resolve my problem.

                          It will be a useful enhancement if these variable expansions are performed by jbpm automatically with a syntax like,

                          ...
                          <action class="org.test.MyAction">
                           <city expression="#{city_param}"/>
                          </action>
                          ...
                          


                          Thanks,