cancel
Showing results for 
Search instead for 
Did you mean: 

setting the value of variable

opal
Champ in-the-making
Champ in-the-making
Hi,

I have the following problem. In the 'DelegateExecution' I store a 'm' variable which is an object of the class Movie and for instance has a field title of type string. Then I display this value in a form using the following piece of code (user can change the value of the field):

<input type="text" value="${m.title}">
Let's make an assumption that I edit this field and change it's value (from "title1" to "title2". Then in the next (next UserTask) step I display the value once again using the following piece of code:

<td>${m.title}</td>
and I expect that the value will be changed to this entered in previous step, but the value is the same. How can I handle this?
8 REPLIES 8

opal
Champ in-the-making
Champ in-the-making
Is it even possible? No ideas?

jbarrez
Star Contributor
Star Contributor
Can't reproduce it here locally.

Can you post a simple version of your form + process?

opal
Champ in-the-making
Champ in-the-making
I will, but need some time to prepare sample.

opal
Champ in-the-making
Champ in-the-making
Ok, I've prepared simplified version o my process.
Here's the bpmn20.xml:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
targetNamespace="http://www.bpmnwithactiviti.org/movieOrder">

<process id="movieOrder" name="Order a movie">
  <startEvent id="start" />

  <sequenceFlow sourceRef="start" targetRef="parseJson" />

  <serviceTask id="parseJson" name="Parse JSON" activiti:class="services.ParseJSONService" />

  <sequenceFlow sourceRef="parseJson" targetRef="assignTechnician" />

  <userTask id="assignTechnician" name="Assign the technician" activiti:candidateGroups="customers" activiti:formKey="assignTechnician.form" />

  <sequenceFlow sourceRef="assignTechnician" targetRef="createMovie" />

  <userTask id="createMovie" name="Create movie" activiti:formKey="createMovie.form"/>

  <sequenceFlow sourceRef="createMovie" targetRef="end" />

  <endEvent id="end" />
</process>
</definitions>
In ParseJSONService I parse the incoming request and store m variable in the context.

public class ParseJSONService implements JavaDelegate {

private GsonMapper gm = new GsonMapper();

@Override
public void execute(DelegateExecution de) throws Exception {
  String mJson = (String) de.getVariable("movie");
  Movie m = gm.fromJson(mJson, Movie.class);
  de.setVariable("m", m);
}
}
Movie:

public class Movie implements Serializable {

private Integer id;
private String title;
private String genre;
private String spiCode;

//public getters and setters
}
In assignTechnician.form I can edit some movie properties (the movie's properties are displaying well):

<div>
<h1>Order</h1>
<table>
  <tr>
   <td>Title</td>
   <td><input type="text" value="${m.title}"></td>
   <td>Genre</td>
   <td><input type="text" value="${m.genre}"></td>
   <td>SPI</td>
   <td><input type="text" value="${m.spiCode}"></td>
  </tr>
</table>
</div>
I expect that on the createMovie.form I will see updated values of movie (changed in assignedTechnician.form) but this doesn't happen. createMovie.form:

<div>
<h1>Order</h1>
<table>
  <tr>
   <td>Title</td>
   <td>${m.title}</td>
   <td>Genre</td>
   <td>${m.genre}</td>
   <td>SPI</td>
   <td>${m.spiCode}</td>
  </tr>
</table>
</div>
My question is: what should be done to see the updated properties o m object on the following forms in my process.

opal
Champ in-the-making
Champ in-the-making
Hi,

Any ideas?

frederikherema1
Star Contributor
Star Contributor
Hi,

The problem is that your form doesn't really set the values from your movie-pojo, you have:

<td><input type="text" value="${m.title}"></td>

While the userguide mentions this, using the "name" attribute on the input-tag:

<input type="text" name="employeeName" value="" />

Currently the REST-API (and explorer) doesn't use the formProperties yet. If these are available, you can specify a mapping from a property on your form to a variable (or even an expression). More info on this can be found in the userguide.

<activiti:formProperty id="title" expression="#{m.title}" required="true" />

As a current workaround, you could add a TaskListener to the userTask on event "end" that invokes setters on your movie-object with properties posted in the form.

opal
Champ in-the-making
Champ in-the-making
Currently the REST-API (and explorer) doesn't use the formProperties yet.

As far as I understand this functionality isn't supported yet?

The workaround might be good idea. Thanks.

frederikherema1
Star Contributor
Star Contributor
Indeed.
The engine API supports this. The REST-API doesn't expose this yet.