7. Server-Side Validation

We use the Hidden Property Pattern to define validation rules without custom XML namespaces.

Mechanism

  • A "Rule Field" is defined as a form property that targets another "Real Field"
  • Naming Convention: The Rule Field ID must be rule_{TargetFieldID}
  • Visibility: The Rule Field must have readable="false" to prevent UI display
  • Storage: The validation rule string is stored in the default attribute

Validation Syntax

Rules use the format keyword(args) with parentheses for XML compatibility.

String Validation

Keyword Arguments Example Description
regex (pattern) regex(^.+@.+$) Validates against Regular Expression
length (min-max) length(10-200) Length between min and max (inclusive)
lengthMin (min) lengthMin(10) Length at least min
lengthMax (max) lengthMax(200) Length at most max

Numeric Validation

Keyword Arguments Example Description
number (min-max) number(18-65) Value between min and max (inclusive)
numberMin (min) numberMin(18) Value at least min
numberMax (max) numberMax(100) Value at most max

Complete Validation Example

<userTask id="registration" name="User Registration">
    <extensionElements>
        <!-- Email Field -->
        <activiti:formProperty id="email" name="Email Address" type="string" required="true"/>
        <activiti:formProperty id="rule_email" type="string" default="regex(^.+@.+\..+$)" readable="false"/>
        
        <!-- Age Field -->
        <activiti:formProperty id="age" name="Age" type="long" required="true"/>
        <activiti:formProperty id="rule_age" type="string" default="number(18-65)" readable="false"/>
        
        <!-- Description Field -->
        <activiti:formProperty id="bio" name="Short Bio" type="string">
            <activiti:value id="type" name="textarea"/>
        </activiti:formProperty>
        <activiti:formProperty id="rule_bio" type="string" default="length(10-500)" readable="false"/>
    </extensionElements>
</userTask>