cancel
Showing results for 
Search instead for 
Did you mean: 

Set Custom Form Type Default Value

kestrel
Champ in-the-making
Champ in-the-making
Hi,

I have created a TextArea custom form type, but it's content value will not be known until runtime. Since I saw  here that the Renderer doesn't have access to the current Process instance/task context, I created an Execution Listener on the SequenceFlow preceding my UserTask that sets the value to a variable.

The problem is, when I use this variable to set the default value of a normal string form type it works, but not when I try to use it with my custom TextArea form type.

How can I set the value of the custom TextArea at runtime?
2 REPLIES 2

trademak
Star Contributor
Star Contributor
Could you share the source code of this custom TextArea?

Thanks,

kestrel
Champ in-the-making
Champ in-the-making
Hi,

I actually figured out a way to pass the parameters I needed into my custom form type's FormPropertyRenderer. On the flow immediately preceding the UserTask with my form, I created an ExecutionListener. It sets the parameter I need for the DB call to a variable, using the same id as the form controls.

<code>
public void notify(DelegateExecution delegateExecution) {
   
  delegateExecution.setVariable("formControlID", "queryParameter");
}


<activiti:formProperty id="formControlID" name="Form Control" type="textArea"></activiti:formProperty>
</code>

Then in my custom form type's renderer, I read the parameter using the formProperty, do my database query, build a string to display in the textArea, then set the value.

<code>
public Field getPropertyField(FormProperty formProperty) {
  TextArea textArea = new TextArea (getPropertyLabel(formProperty));

                String queryParameter = formProperty.getValue();

                // Do DB query, build resultString.

                textArea.setValue(resultString);

                return textArea;
}
}
</code>

As long as the id of the variable matches the id of the form control, I can reuse a handful of custom form properties (TextArea, ComboBox, TwinColSelect, etc) for many form controls simply by setting more variables in the listener and on the form.