cancel
Showing results for 
Search instead for 
Did you mean: 

Allowing expressions in properties of CustomServiceTask

f3lix
Champ in-the-making
Champ in-the-making
Hello,

I followed the user guide and successfully added and entry to the designer's palette by extending AbstractCustomServiceTask and adding the appropiate annotations.

If i have a text property like this:


@Property(type = PropertyType.TEXT, displayName = "Service endpoint URL")
private String endpointURL;

the user can enter text for the field endpointURL, but I also want to allow expressions for this field. How can I do this?

Or put it another way: currently the generated BPMN2 XML will look like this:

   <activiti:field name="endpointURL">
          <activiti:string>${endpointUrl}</activiti:string>
    </activiti:field>

How do I get the following (with AbstractCustomServiceTask 😞

   <activiti:field name="endpointURL">
          <activiti:expression>${endpointUrl}</activiti:expression>
    </activiti:field>

Regards,
Felix
4 REPLIES 4

tiesebarrell
Champ in-the-making
Champ in-the-making
Good point. This is something we should support. As a start we could detect whether you entered a string that is probably meant as an expression and generate the other item instead - I'm not sure whether we can effectively catch other scenarios with mixed strings like "ms ${piggy} went to town". One thing I'll need to check is whether the injection in the runtime class needs adjustment or not. Can you please create a Jira issue that references this thread  and assign it to me (Tiese Barrell)? Then I'll make sure it makes its way into Designer. Thanks.

f3lix
Champ in-the-making
Champ in-the-making
Thanks for your fast response.

I created a ticket (http://jira.codehaus.org/browse/ACT-877) but could not assign it to you.

Felix

tiesebarrell
Champ in-the-making
Champ in-the-making
Great, thanks. I forgot you can't assign it directly. I claimed the issue.

f3lix
Champ in-the-making
Champ in-the-making
For now I created a workaround by evaluating the expression within the JavaDelegate, so <activiti:string> will also be evaluated as expression.


public class QueryDelegate implements JavaDelegate

Expression query;
Expression endpointURL;

@Override
public void execute (DelegateExecution execution) throws Exception
{
  ExpressionFactory ef = new ExpressionFactoryImpl ();
  ELContext context = new ActivitiElContext (new VariableScopeElResolver (execution));
 
                // instead of: String queryString = (String)query.getValue (execution);
  ValueExpression ex = ef.createValueExpression (context, query.getExpressionText (), String.class);
  String queryString = (String) ex.getValue (context);
            
               // instead of: String endpointUrlString = (String)endpointURL.getValue(execution);                      
  ex = ef.createValueExpression (context, endpointURL.getExpressionText (), String.class);
  String endpointUrlString = (String) ex.getValue (context);

              …
        }
}

I am not sure if this will break something, but it seems to work … Smiley Wink

Regards,
Felix