cancel
Showing results for 
Search instead for 
Did you mean: 

Default values for Activiti form properties

thilo_ginkel
Champ in-the-making
Champ in-the-making
Hi there,

we are using Activiti's FormService to attach custom form properties to tasks, e.g.:


    <userTask id="usertask1" name="Task 1"" activiti:candidateGroups="Group">
      <extensionElements>
        <activiti:formProperty id="someProperty" name="Some Property" type="boolean" required="true" readable="true" writable="true"></activiti:formProperty>
      </extensionElements>
    </userTask>
What I would like to do, though, is to initialize the property with a default value in case no variable someProperty has been created in the process context so far.

I tried attaching an expression to the property, but this variant does not work as Activity will attempt an assignment to the expression on save, which will obviously fail:


    <userTask id="usertask1" name="Task 1"" activiti:candidateGroups="Group">
      <extensionElements>
        <activiti:formProperty id="someProperty" name="Some Property" type="boolean" required="true" readable="true" writable="true" expression="${false}"></activiti:formProperty>
      </extensionElements>
    </userTask>
org.activiti.engine.impl.javax.el.ELException: Cannot set value of a non-lvalue expression 'false'
   at org.activiti.engine.impl.juel.AstRightValue.setValue(AstRightValue.java:53)
   at org.activiti.engine.impl.juel.AstEval.setValue(AstEval.java:86)
   at org.activiti.engine.impl.juel.TreeValueExpression.setValue(TreeValueExpression.java:138)
   at org.activiti.engine.impl.delegate.ExpressionSetInvocation.invoke(ExpressionSetInvocation.java:37)
   at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
   at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
   at org.activiti.engine.impl.el.JuelExpression.setValue(JuelExpression.java:69)
   … 118 more
Now I thought about adding some kind of default expression that is used to initialize a form property iff the backing variable does not yet exist in the current execution scope.

What are your thoughts about this? If you think that this makes sense I would go ahead and contribute a patch…

Regards,
Thilo
12 REPLIES 12

trademak
Star Contributor
Star Contributor
Hi,

Right, a default or an initial value (with an expression) is not implemented.
So if you would be willing to contribute a patch that would be great.
Maybe you can use an attribute name like default that could hold a static String or an expression?

Best regards,

thilo_ginkel
Champ in-the-making
Champ in-the-making
Right, a default or an initial value (with an expression) is not implemented.
So if you would be willing to contribute a patch that would be great.
Maybe you can use an attribute name like default that could hold a static String or an expression?
Sounds good. I'll open a JIRA issue and attach a patch as soon as it is ready.

Regards,
Thilo

thilo_ginkel
Champ in-the-making
Champ in-the-making
JIRA: http://jira.codehaus.org/browse/ACT-1028

My current patch candidate (attached to the JIRA issue above) makes a couple of assumptions:
  • Providing a required property on submitTaskFormData is no longer mandatory iff a default is maintained (in this case the default is saved)

  • If the default expression returns a java.lang.String, this is result is directly set as form property instead of routing it through the FormType for conversion

  • OTOH, when applying the form property default in submitFormProperty, routing it through convertFormValueToModelValue is strictly required
I tried to mimic the code style already used in FormPropertyHandler, but due to the fact that white space around operators was already used inconsistently, I had to go for one of them. 😉

I'd appreciate your feedback.

Thanks,
Thilo

backslash
Champ in-the-making
Champ in-the-making
Hello guys,
sorry for reviving old topic. I was looking for exactly the same thing as thilo.ginkel and then I discovered that the patch(and also Activiti 5.9) is only working for UserTask forms and not for StartEvent forms. The reason is obvious from the source code. The whole default value assignment is under "execution != null" test, which evaluates to false because the process did not started yet.

I had make a simple modification to the logic and its working for me now. But I am new to Activiti development, so I dont really know if I should create new JIRA or update the aforementioned.

trademak
Star Contributor
Star Contributor
Hi,

Please reopen the current JIRA and attach your patch to it.

Thanks,

hheg8837
Champ in-the-making
Champ in-the-making
We also desperately need working default value fields in Activiti Explorer …

It would be very nice if there was a bit feedback on this issue …

All the best,
Thomas

frederikherema1
Star Contributor
Star Contributor
I ran into this kind of thing before. Since the start-form is populated BEFORE the process starts, there is no execution. This may not sound like a big deal, but the form-property values are created using expressions. You can't evaluate an expression agains an execution if there is no execution yet.

The ExpressionManager expects a VariableScope to resolve variables agianst. We could add a dummy-scope which contains no variables, allowing the defaults to be initialized even without an expression. Although this is a bit fishy (implementation detail), this should get fixed. I'll look into it

http://jira.codehaus.org/browse/ACT-1028

frederikherema1
Star Contributor
Star Contributor
Added solution for this issue + included tests. Checked in on trunk, will be in 5.10 (https://fisheye.codehaus.org/changelog/activiti?cs=3555)

hheg8837
Champ in-the-making
Champ in-the-making
Thank you very much! Smiley Happy