Validation - Form Properties

Showing results for 
Search instead for 
Did you mean: 
Member II

Validation - Form Properties

I have a requirement to have strict validation of form properties (i.e) activiti should only save the exact form properties that are defined as part of extension elements under a user task. 

Assume I have a userTask with some form properties attached.

<userTask id="usertask1" name="Submit Form">
        <activiti:formProperty id="name" name="Name" type="string" variable="name" required="true"></activiti:formProperty>
        <activiti:formProperty id="age" name="Age" type="string" variable="age" required="true"></activiti:formProperty>   

On POST, I build the variables from the request and invoke the below line of code to save the values and complete the task.

formService.submitTaskFormData(taskId, variables);

If I don't pass any of the defined properties, the system spits out an exception stating "form property ..... is required". This is good. My issue is if I pass in any additional value as a form property like 'address', activiti accepts it and saves it.

Is it possible for me to tell activiti to accept only the two properties that are defined and throw an exception if any additional properties are sent in? If there is no straightforward solution to it, what is best way for me handle/validate this?

1 Reply
Alfresco Employee

Re: Validation - Form Properties

I think it would be possible for you to write code that would retrieve the extension elements and then validate that the variables are only for these elements (assuming you do have to look these up at runtime and have to get them from the definition). There is code which looks up elements in this way in this post - How to get a custom properties from UserTask