cancel
Showing results for 
Search instead for 
Did you mean: 

ServiceTask delegateexprssion is not honoring field settings

kesavkolla
Champ in-the-making
Champ in-the-making
If the service task is defined with delegateexpression it's not honoring fields that are defined in BPMN.  The delegate gets instantiated but the fields are not set.

The code in BpmnParse.java line 902 when creating ServiceTaskDelegateExpressionActivityBehavior the fields are not parsed.  Also the code ServiceTaskDelegateExpressionActivityBehavior doesn't handle the fields.

To me it's a defect even when we define delegate expression to load any spring bean we still want to wire some properties of that in BPMN.  IMO the BPMN field definitions should be applied to delegate object.

I've patched the code I can submit the code if any one interested.
8 REPLIES 8

trademak
Star Contributor
Star Contributor
Hi,

In the user guide it says "Field injection is supported when using the 'class' attribute".
So it's not a bug, but more a feature request.
Could you explain your use case a bit more? What would you like to inject?

Best regards,

sangv
Champ in-the-making
Champ in-the-making
I am facing the same scenrio when working with 5.7 Activiti. I have this in my process

<serviceTask id="servicetask1" name="My Task Execution Service" activiti:delegateExpression="${testExpressionDelegate}">
      <extensionElements>
        <activiti:field name="field1">
          <activiti:string>name</activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>

Where testExpressionDelegate is a Spring bean (which I am using as my delegate expression.) for a class that implements JavaDelegate

public class MyTaskDelegate implements JavaDelegate {

@Autowired
private Service service;

private Expression field1;

/**
  * @see org.activiti.engine.delegate.JavaDelegate#execute(org.activiti.engine.delegate.DelegateExecution)
  */
@Override
public void execute(DelegateExecution delegateExecution) throws Exception {

  if (field1 != null) {
   String field1AsString = (String) field1.getValue(delegateExecution);
   …
  }

}

But the field1 is always null. Like you said, the field1 gets a value if I use this directly as a java class but I want to wire some things into this class and cannot use it like that.

Please let me know if you want more details or if this feature has already been added.

Thanks,
Sang

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
this is not supported… with expressions you can pass in parameters IN the expression, so that is the 'workaround'

sangv
Champ in-the-making
Champ in-the-making
Well I understand that it can be done with expressions but I was using delegateExpression implementing the JavaDelegate interface so that I could get access to context (and all the process variables etc and not have to pass everything in as a parameter). Well, as a workaround I added an execution listener to the task and used that to interpret the field expressions.

<activiti:executionListener event="start" class="MyTaskListener">
public class MyTaskListener implements ExecutionListener {

private Expression field1;

@Override
public void notify(DelegateExecution paramDelegateExecution) throws Exception {

  if (field1 != null) {
   paramDelegateExecution.setVariableLocal("field1", field1.getExpressionText());
  }

}

Then I can get the field on my Service task delegate class (wired thro spring)
Object field1 = delegateExecution.getVariableLocal("field1");
Let me know if you have any comments on this.

Thanks,
Sang

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Anyone still interested in having this 'fixed'? (I volunteer)

adrobisch
Champ in-the-making
Champ in-the-making
Yes, please add this. It's also important for Activiti OSGI (which only supports delegateExpression).

bernd_ruecker
Champ in-the-making
Champ in-the-making

marcelwolf
Champ in-the-making
Champ in-the-making
Is there something new about this?

I try to use it OSGI context and if i try to pass Expressions into my cached bean i got an error :

<blockcode>
Process task 302639 was signaled to leave.
2016-11-24 08:35:07,083 | WARN  | m://client_queue | BpmnProducer                 | 45 - logger-logging - 1.0.0 | Error while Calling BPMN: org.activiti.engine.ActivitiIllegalArgumentException: Field definition uses unexisting field 'moduleName' on class Proxy8477823f_cf1d_4efb_8912_0b18301965d9
ActivitiIllegalArgumentException: Field definition uses unexisting field 'moduleName' on class Proxy8477823f_cf1d_4efb_8912_0b18301965d9

</blockcode>

i Use Version 5.19.3