I am currently working on a small Camunda program to familiarize myself with it.
My current problem is this:
In a service task, I save an entity in the Database, created by typing. So far so good, that works. The next task is a UserTask in which the Entity should be reissued. To realize this, I have the ID of the created entity, by means of DelegateExecution, stored in a variable (in the ServiceTask). In the following UserTask I want to read this variable again but it is no longer available.
What can this be?
I have already realized other small programs in Camunda before and it worked there.
@Named
@Stateless
public class SpeichernController implements Serializable {
@Inject
private AusschreibungService ausschreibungService;
public void speichern(DelegateExecution execution) throws IOException {
Map<String, Object> processVariables = execution.getVariables();
Ausschreibung ausschreibung = new Ausschreibung();
ausschreibung.setName((String) processVariables.get("name"));
ausschreibung.setVon((LocalDate) processVariables.get("von"));
ausschreibung.setBis((LocalDate) processVariables.get("bis"));
ausschreibung.setAnforderungen((List<Anforderungen>) execution.getVariable("anforderungen"));
execution.removeVariables(processVariables.keySet());
ausschreibung = ausschreibungService.speichern(ausschreibung);
execution.setVariable("id", ausschreibung.getId()); // There I set the variable
ServerLogger.log("ID -> " + execution.getVariable("id"));
}
}
I save the variable with execution.setVariable(…);
For the usertask I have created a JSF with a BackingBean:
This ist the Methode witch ist called from the JSF Page:
public Ausschreibung getAusschreibung() {
Integer id = businessProcess.getVariable("id"); // There i want get the variable
ServerLogger.log("ID -> " + id);
if (ausschreibung == null) {
ausschreibung = ausschreibungService.find((int) businessProcess.getVariable("id"));
}
ServerLogger.log(ausschreibung.toString());
return ausschreibung;
}
In the Top of the Backing BEan i Inject he BusinessProcess. Then i want to get the variable with i have set in the Usertask, but the variable returns null.
The output of the ServerLogger.log ,at the Service Task, is 1. It is the correct id.
In the User Task is the output is null.
The output of the exception is a Null Pointer Exception.
The Exception flies in this Line in the User Task: ausschreibung = ausschreibungService.find((int) businessProcess.getVariable("id"));
With this line I delete only the variables from the map. Map <String, Object> processVariables = execution.getVariables ();
I delete all the variables I do not need anymore.
I tried to comment on the line, but that does not help.
And in the line below the line that sets the variable, the varable is present.
execution.setVariable("id", ausschreibung.getId()); // There I set the variable
ServerLogger.log("ID -> " + execution.getVariable("id")); // There I get the variable and it displays 1
camundaTaskForm.startProcessInstanceByKeyForm() should be used in the start form
camundaTaskForm.startProcessInstanceByKeyForm() method which extracts the process definition key from the URL and starts a conversation for the start form.
camundaTaskForm.startTaskForm() should be used in subsequent task forms
camundaTaskForm.startTaskForm() method which extracts the task id from the URL and starts a conversation for the task form