Workflow and Form Builder with Custom Validator

Once I had a requirement for a project as follow :

  • A web application
  • Dynamic form builder, that can be build by business users instead of IT developers. The form builder must be extensible that business users can add any validation to an existing database ( let  say, to validate if a company name key in to a field already exists in database), without IT dependency in the future
  • Form created must be able to be attached to a workflow, and the flow could be defined by business users without dependency to IT in the future
  • There must be a role-based access control where users can be grouped into role to assign fine-grained permissions

What I proposed for solution:

Using activiti workflow engine as based product, where it has the workflow engine and workflow designer, and also workflow runtime as a web application including the role-based access control.

What I needed to figure out :

  • A way for business users to “attach” validation rule without having to write any code (the code already provided by IT as foundation)

In activiti, there’s a way to define form’s property renderer and form’s property type ( see this link )

Let’s take a look at form definition created using form designer :

Workflow definition can be deployed as activiti explorer’s plugin, along with java classes for custom form type. Remember our custom form type here will have “string-with-custom-validation” type.

To have custom form type, we need to extend org.activiti.engine.impl.form.FormTypes . Our example class will be CustomFormTypes below that extends FormTypes that renders custom properties on forms. There’s another class which extends activiti’s class, to handle String type property. see below

I added several properties on CustomValidationStringFormType  class which purpose I will explain in later class.

Another class is needed to tell the engine how to render CustomValidationStringFormType

And finally, the action to validate, which basically call a JSON web service on a specified URL

In my web service endpoint, here is how I handled the validation. Table name, and value to check would be taken from parameters that send by activiti explorer’s custom plugin

The base class for this is responsible to define treatComparisonValue method as follow


Leave a Reply

Your email address will not be published. Required fields are marked *