Form validation

On the Process Platform, the user’s input are validated on the server-side. The field value is being sent to the server and if the validation fails, the response is sent back to the client and a feedback is shown underneath the field.

The Process development kit provides a framework to develop classes for validating user’s input on the server-side.

The Validator Framework gives a standard way for defining :

  • an XML definition file: an association between the name of the validator and its class full qualified name.
  • a validator class: class to execute while validating.

Validator definition

XML definition

The XML validator file should be deployed on the custom/validators folder. Its name must be unique on the Process server.

To prevent name conflicts it is recommended to use the following template: companyName-validators.xml (e.i. visiativ-validators.xml).

This XML definition file provides all the necessary information to describe several validators:

  • Validator name: the name should be unique on the Process server.
        <validators> 
            <validator name="demo" class="com.axemble.vdoc.education.validators.DemoValidator" parameter="false" options="ignoreCase" />
        </validators>
  • Validator runtime class: the full qualified name of the validator class to execute while validating a field.
  • parameter: one of the following values: true, false or mandatory. mandatory if the parameter is mandatory, true if the parameter is optional and false if the validator does not required any parameter.
  • options: a set of comma-separated options.
  • hidden: if true, the Framework prevents the validator to appear on the Studio.

Runtime class

A runtime class is a Java class which will be called by the framework when the UI Framework validates any form fields. A runtime class must extend the com.axemble.vdoc.sdk.validators.BaseValidator<T> class. The BaseValidator class uses a generic to validate any kind of object.

By creating a validator runtime class you need to implement two methods:

  • validate(): this method receives the object to validate and the parameters to use for the validation. The return value returns true if the object is valid, false otherwise.

Another method could be overridden:

  • getErrorMessage(): Allows to override a unique error message to display when the validation fails.

Create the runtime class for the validator

package com.axemble.vdoc.education.validators;

import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.axemble.vdoc.sdk.validators.BaseValidator;

public class DemoValidator extends BaseValidator<String> {
	@Override
	public boolean validate( String object, List<String> parameters ) {
		if ( parameters != null && parameters.size() > 0 ) {
			String arg = parameters.get( 0 );

			// checks if the 'arg' parameter is contained within the 'object'
			boolean ignoreCase = parameters.size() > 1 && parameters.get( parameters.size() - 1 ).equalsIgnoreCase( "--ignorecase" );
			return ( StringUtils.isNotEmpty( object ) && 
					StringUtils.isNotEmpty( arg ) && 
					( ignoreCase ? ( object.toLowerCase().indexOf( arg.toLowerCase() ) != -1 ) : ( object.indexOf( arg ) != -1 ) ) );
		}
		return false;
	}

	@Override
	public String getErrorMessage() {
			return getStaticString( "LG_DEMO_ERROR_MESSAGE" );
	}
}

Available validators

The Process Platform has a wide range of validation functions. Designers can change the default validation behavior by specifying a list of rules on each input field through the property panel within the Form Designer.

Name Description Attributes
alphanumeric The input requires an answer that contains only letters a-z and numbers alphanumeric
alpha The input requires an answer that contains only letters a-z alpha
capitalize The input requires an answer that starts with upper case character capitalize
email The input requires an answer that contains matches the email format email
url The input requires an answer that contains matches the url format url
maxchars The input checks that contains more than maxchars characters maxchars number_of_characters
minchars The input checks that contains less than minchars characters minchars number_of_characters
contains The input checks that the answer contains the specified text contains text --ignorecase
startswith The input checks that the answer starts with the text startswith text --ignorecase
endswith The input checks that the answer ends with the text endswith text --ignorecase
lowercase The input requires an answer with only lower case characters lowercase
uppercase The input requires an answer with only upper case characters uppercase
sysname The input requires an answer that matches the system name rules : - only letters a-z, A-Z, numbers or underscores - no number on first character sysname
extensionformat The input checks that the answer matches the full qualified name for a class. extensionformat
regexp The input checks that the answer matches the expression.
Example to allows only lower case letters regexp : ^([a-z]+)$
regexp expression --ignorecase --multiline

Text validator for FileCenter objects

This validator is available in the Studio, in the form part, for text fields.

This validator is used to check that a character string can be used as the name of a document, folder or FileCenter document space.

The forbidden characters, checked on registration are: \ / : * < > | " ?

Info

These characters are prohibited both for “Process” reasons but also for reasons specific to the Windows OS (display of folders and files in Windows Explorer using the http dav / WebDav protocol).

Source : https://wiki.myvdoc.net/xwiki/bin/view/Dev+Floor/ValidatorFileCenterString