Development tools : XUI editor : Editing an XUI page : Editing the properties of the XUI widgets : Defining cross-field validation in a form
  
Defining cross-field validation in a form
Cross-field Validation is used to validate multiple fields in a form if their values are correlative.
For example, on most account registration forms, there are two password inputting fields. In order to avoid customers inputting wrong password accidentally, both fields must have the same value before the form can be submitted.
This graphic is described in the surrounding text.
See
Defining xValidation in XUI editor
Cross-field validation process in client side and server side
Synchronizing the isMandatory values of form inputs between client and server
xValidationErrorHandler interface
See also
Editing the properties of the XUI widgets
Defining xValidation in XUI editor
You can use xValidation section in Form widget to define cross-field validation easily. This page will provide the detailed process.
Prerequisite
The cross-field validation from server side are enabled by default. Make sure these codes are in btt.xml:
in the HTML section
<field id="serverXValidation" value="true" />
in the formatter's class table section
<field id="condition" value="com.ibm.btt.form.xval.FormXValidation" />
<field id="xValConditions" value="com.ibm.btt.form.xval.FormXValidations" />
About this task
In Condition, users can define how multiple correlative fields in a cross-field validation are valid or not valid, and the hint message will to be shown if values of correlative fields are not valid.
Note To directly provide codes for cross-validation on server side, see Performing cross-field validation.
Procedure
To define a cross-field validation, do the following steps:
In the Project Explorer View, open a XUI file and select the form which you want to define cross-field validation.
In the xValidation tab of Properties view, click the Add icon This graphic is described in the surrounding text. to add a new xValidation rule.
This graphic is described in the surrounding text.
Headless xValidation has a small decoration beside it.
This graphic is described in the surrounding text.
In Basic tab of Details section, input the name and the hint message which will be shown when the values of correlative fields are not valid in Hint field. Hint message supports NLS, you can select NLS element by clicking Browse button. Choose to define either invalid condition or valid condition by clicking the "Invalid condition" checkbox.
Select Condition tab of Details section to define condition of this validation. You can either choose Widget Function, Widget Property, Expression or Global Function to define the condition of this cross-field validation, and then click Apply Value to confirm.
This graphic is described in the surrounding text.
See also
Defining cross-field validation in a form
Cross-field validation process in client side and server side
The validation can be executed from both client side and server side. This page will introduce the validation process and rules in both client-side and server-side.
Client-side behavior
In client-side, when any field in the form is changed (lost focus), the form will directly invoke the xValidation rules developers have defined and selectively pop up the hint message. Until all the cross-field validations are valid, submit buttons in the form will be disabled and no data can be submitted to the server.
When a cross-field validation rule is not valid, and there is no single-field validation failed, the hint message of the invalid cross-field validation rule will be shown. If a form has multiple cross-field validation rules, and more than one rules are not valid, only one hint message of invalid rule will be selected and shown on the form. The message of invalid rules is selected according to:
If the last changed field is belonged to a cross-field validation rule, and all other fields in the rule have their values.
If no rule can be found in 1, then choose the first invalid rule according to definition sequence.
This graphic is described in the surrounding text.
Server-side behavior
If the client-side validation are accidently shut down or hacked by purpose, the form is submitted to the server. Then the server-side validation will be invoked.
Among all the xValidation rules you have defined, headless xValidation will be generated into a file under the definitions.operation folder.
In the server side, only the headless xValidation rules will be executed.
Headless xValidation has headless conditions, including:
Widget function: no headless widget functions
Widget property: those mapped to a context dataName.
 
Widget
headless property
TextBox
value
Combo
value
Radio
value
Checkbox
isChecked
SelectList
value
MultiSelect
value
CheckedMultiselect
value
EnhancedMultiselect
value
RichText
value
TextArea
value
Tree
value
HiddenField
value
Expression: those in which both left and right components are headless
Global function: all functions available at the server side, as defined in their configuration, are headless
Constant: All constants
When a cross-field validation rule is not valid in the server side, an error message page will be shown.
This graphic is described in the surrounding text.
See also
Defining cross-field validation in a form
Synchronizing the isMandatory values of form inputs between client and server
1 Enable the cross-field validation from server side are enabled by default. Make sure these codes are in btt.xml:
in the HTML section:
<field id="serverXValidation" value="true" />
in the formatter's class table section:
<field id="condition" value="com.ibm.btt.form.xval.FormXValidation" />
<field id="xValConditions" value="com.ibm.btt.form.xval.FormXValidations" />
2 Update the ECA RuleLabelProvider to support the decoration:
This graphic is described in the surrounding text.
If ECA condition is the headless condition and it only contains action (include true/false actions) which modifies the “isMandatory” value of an input widget, the tooling displays a decoration icon in the ECA rule Label but not in the rest of ECA rules. The <mandatories> ID is same with the ECA rule ID.
This graphic is described in the surrounding text.
Note The headless icon dynamically updates if the ECA value changes.
3 See the following generate relationship:
This graphic is described in the surrounding text.
An xml file that contains the ECA rules will be generated in definitions/operations/. Keep the feature on and then the server side will use the ECA rules in this file to update the isMandatory properties.
See also
Defining cross-field validation in a form
xValidationErrorHandler interface
You can implement the xValidationErrorHandler interface to handle the x-validation errors.
public interface xValidationErrorHandler {
public void handleError {Exception e, ChannelContext channelCtx, PresentationHandler prsentHandler) ;}
}
You can define xValidationErrorHandler in btt.xml > ChannelHandler > HTML.
This graphic is described in the surrounding text.
If xValidationErrorHandler is not defined in btt.xml > ChannelHandler > HTML, the default handler will be used for server side x-Validation error. The default behavior is to render UDTT error page and print error in browser and in log file.
This graphic is described in the surrounding text.This graphic is described in the surrounding text.
See also
Defining cross-field validation in a form