cancel
Showing results for 
Search instead for 
Did you mean: 

Filling the form fields by values from external system.

mutcha
Champ in-the-making
Champ in-the-making
Let's say I have prepared bpmn20.xml file with process, where one of tasks has defined simple form, so In the Eclipse designer in the properties of the task in "Form" section I added few textfields in the form. Then I upload this deployment to Activiti Explorer. Is it possible when the form for the task is shown - to fill these textboxes by values which could come from external system for example Web Service Method? Let's say the process is started with some variables, and then when form is shown these variables are used as parameters for method of some external webservice which returns some value, and this value is put to the text box of the form. Is such scenario possible? If so then How to achieve it ?
12 REPLIES 12

frederikherema1
Star Contributor
Star Contributor
If you mean that, every time the form is going to be shown, at that moment, a call is done to fill in the values? Than no.

What you can do with the out-of-the-box explorer is have a task-listener on the task which does the webservice-call and fills in some variables on the task/process. Your formProperties can use the "variable" attribute to point the the variable, holding the value looked up in your web service. However, this is done ONLY ONCE, when the process flow reaches the user-task and waits there.

The form-property mechanism is pluggable, so you could have a property of type "custom" that does the webservice-call. This will require somme plugging in your explorer-configuration but is quite simple. Alternatively, you can also alter the UI based on the special types, this is also pluggable.

mutcha
Champ in-the-making
Champ in-the-making
Thanks for reply.
Do you know any example of task listener, how to implement it? some tutorial or maybe some project example which I could download?

mutcha
Champ in-the-making
Champ in-the-making
And also can I use the "variable" approach to fill the comboboxes with some many options ?

mutcha
Champ in-the-making
Champ in-the-making
Ok, I found the example in the user guide.

frederikherema1
Star Contributor
Star Contributor
Please consult userguide before asking questions. It contains tons of stuff http://activiti.org/userguide/index.html#taskListeners.
If you want the combo-boxes populated with values that are not defined in the process, you'll have to plug in your own FormProperty:

Example of this is in explorer itself:
- org.activiti.explorer.form.UserFormType
- UI for it: org.activiti.explorer.ui.form.UserFormPropertyRenderer
- Both classes plugged in into context-file

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Uhhmm… Can't you have the expressions of form properties point to a cdi bean which when called does some logic, e.g. Retrieve info from a database?

frederikherema1
Star Contributor
Star Contributor
Ronald, you can. However, this only works when the form-property is read-only. If that's not the case, when submitting the values, the expression will be used to "set" (which will fail).


if (modelValue != null) {
      if (variableName != null) {
        execution.setVariable(variableName, modelValue);
      } else if (variableExpression != null) {
        variableExpression.setValue(modelValue, execution);
      } else {
        execution.setVariable(id, modelValue);
      }
    }

mutcha
Champ in-the-making
Champ in-the-making
Ok, I am testing the approach with Task Listener at the creation of the task, but the class of task listener is not loaded in Activiti-Explorer.
I've read some posts to handle it and I found that jar must be exported using normal Eclipse Export method but still I have a problem.
I got following exception during starting of the process after deployment.
Cause: org.activiti.engine.ActivitiException: Exception while invoking TaskListener: couldn't instantiate class mhcc.app.incidentservice.app.internal.Listener

This is how my Task definition looks like (just part of the xml file)
<userTask id="usertask1" name="Describe the accident" activiti:assignee="kermit">
      <extensionElements>
        <activiti:taskListener event="create" class="mhcc.app.incidentservice.app.internal.Listener" />
      </extensionElements>
</userTask>

This is my class of listener:
package mhcc.app.incidentservice.app.internal;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;

/**
* Listener for Task
*/
public class Listener implements TaskListener {

    /**
     * @see org.activiti.engine.delegate.TaskListener#notify(org.activiti.engine.delegate.DelegateTask)
     */
    @Override
    public void notify( DelegateTask delegateTask ) {
        delegateTask.setVariable( "Vehicle", "Funkerss" );
    }
}

I copied this jar to directory in the Activiti-Explorer:
setup\build\webapps\activiti-explorer.war\WEB-INF\lib

In the attachments I present the steps I made during export.
After I copied the Listener.jar I restarted Activiti-Explorer by:
ant demo.stop
ant demo.start

Have someone idea what I'm doing wrong? I'm quite new in java, maybe I missed something obvious in the xport process of jar or restarting of activiti-explorer??
Thanks in advance.

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Ronald, you can. However, this only works when the form-property is read-only. If that's not the case, when submitting the values, the expression will be used to "set" (which will fail).


if (modelValue != null) {
      if (variableName != null) {
        execution.setVariable(variableName, modelValue);
      } else if (variableExpression != null) {
        variableExpression.setValue(modelValue, execution);
      } else {
        execution.setVariable(id, modelValue);
      }
    }

Why would calling a setter fail? If you have a getter and setter (and no 'actual' db work should not be done in the getter) and the setter stores things?

(Still glad we do not use the formproperties for actual form stuff, more in a way of having 'task parameters' :-))