cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping a start event form property to a java bean

rainerv
Champ in-the-making
Champ in-the-making
Hi,

How would it be possible to assign values from Java beans to start event form properties?

It seems that mapping form properties to Java beans doesn't work in start events (it works with user tasks, though). If a start event has form properties which are mapped to a Java bean properties, then the bean values are not assigned to the form properties by the Activiti Engine.

Here is an example from the Activiti User Guide which describes mapping a form property street to a Java bean property address.street in a user task using the expression attribute:

<activiti:formProperty id="street" expression="#{address.street}" />

This works perfectly well in user tasks but not in start events, which might be a bug in the Engine.

But if it's indeed an intended "feature", then how would it be possible to assign values from Java beans to start event form properties?

My other concern is similarly related to built-in form rendering: how would it be possible to access Java beans in forms as in the following example (where address would be a Java bean):

<input type="text" name="street" value="${address.street}" />


Accessing Java beans in a start event's form properties and forms would allow more dynamic workflows where some information could be accessed from a system and shown to a user when the user is starting a new process by submitting a form (properties).

I would appreciate any thoughts and guidelines in this.

Thanks!
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
Hi,

When you use ${address.street} as form-property, the form-engine expects a variable with name "address" on the process. Since the process is just starting, no variables are available, so address cannot be resolved. For the engine, there really is no way of knowing how to instantiate/find the address bean.

The example in the userguide, using the address-bean, assumes a bean address is available on your process, which has been set by eg. API (runtimeService.setVariable) or from inside the process (JavaDelegate, Tasklistener etc.).

A simple workaround for this could be to store the street as a normal variable and add a ExecutionListener to the start-event, which instantiates a new Address-bean and sets the address-beans properties based on the earlier submitted variables.

<startEvent id="theStart" />
   <extensionElements>
      <activiti:executionListener class="org.activiti.CreateAdressBeanListener" event="end" />
    </extensionElements>
</startEvent>

public class CreateAdressBeanListener implements ExecutionListener {

  public void notify(ExecutionListenerExecution execution) throws Exception {
    Address address = new Address();
    address.setStreet(execution.getVariable("street");
    address.setXXX(…);
    …
    execution.setVariable("address", address);
  }
}

If you want to show existing (non-process variables) data in your startform, you can always expose your data/services providing the data using spring. You can define a bean in your spring-configuration (the same configuration where your process-engine is in) and use the beans in your expressions, eg:

<activiti:formProperty id="street" expression="#{addressService.getAdress('Belgium')}" />

Hope this answers your questions.
Cheers

rainerv
Champ in-the-making
Champ in-the-making
If you want to show existing (non-process variables) data in your startform, you can always expose your data/services providing the data using spring. You can define a bean in your spring-configuration (the same configuration where your process-engine is in) and use the beans in your expressions, eg:

<activiti:formProperty id="street" expression="#{addressService.getAdress('Belgium')}" />

Thank you for the answer.

I'm indeed using Spring and trying to access my services as Spring-configured beans in start forms.

Interestingly, I'm able to access my services in form properties in user tasks, but not in form properties in start events. Actually, I'm able to access my Spring-configured beans in all the other workflow elements (service tasks, task listener etc) but not in start events.

Could it be a bug in the Engine where beans are accessible everywhere else but start events or could there be just something wrong with my application? Could someone confirm (and test) if beans really work in start events?

Thanks again

frederikherema1
Star Contributor
Star Contributor
Hi,

I've looked a bit deeper into this and found the reason why this is happening.

The expression-resolving is now depending on an execution being active. When requesting start-form data, no execution is active yet, and the expression is not resolved, rather than throwing an exception. But it's a valid usecase to use expressions without an active execution in the start-form properties when using spring, like you are trying to do.

Created an issue for it, so you can track the changes: http://jira.codehaus.org/browse/ACT-558. I propose you use the workaround I suggested, using ExecutionListener on startEvent END.

rainerv
Champ in-the-making
Champ in-the-making
Thank you, I appreciate that.
Looking forward to the bug fix.