After Completing This Task: This section describes how to perform data field syntatic validation, data field semantic validation, and cross-field validation.
Each typed data field must define its required syntactic validation in the dsetype.xml file.
You can also use the validation process in the startup sequence by passing data through the request to the CSEstablishSessionServlet. The startup operation may define its typed data elements with the same validators.
For an example of how data field validation works on a data field with the "Amount" data type, see the following in the HTML Sample Application:
▪ accountTransferData.amount data field in accountTransferOp.xml
▪ Amount type in dsetype.xml
▪ com.ibm.btt.samples.html.AmountValidator class
▪ <dse:text dataName="amount" error="yes" size="10" maxLength="10"/> in transfer.jsp
To implement semantic validation for an operation, do the following:
1 If the operation does not already implement the OperationXValidate cross-field validator interface, implement it.
2 Write the validate(String, DataField, Context) so that it checks the value of the field against one or more business rules.
3 Make the validate method throw a DSETypeException if the data is not valid for the field.
To implement semantic validation for a processor, do one of the following:
▪ Use the same procedure you use to implement semantic validation for an operation except that the processor implements the ProcessorXValidate interface.
▪ Have the processor extend the HtmlProcessorXValidate class, which already implements the ProcessorXValidate interface. Override the doValidate(String, DataField, Context) method to perform the semantic validation.
For an example of how semantic data field validation works on a data field, see the following in the HTML Sample Application:
▪ validate(String fullyQualifiedName, com.ibm.btt.base.DataField df, com.ibm.btt.base.Context ctxt) method com.ibm.btt.samples.html.AccountTransferXVal class
▪ <dse:text dataName="amount" error="yes" size="10" maxLength="10"/> in transfer.jsp
Each business operation is responsible for cross-validating the data by doing the following:
▪ Subclassing the DSEXValidate abstract class
▪ Implementing the corresponding interface (OperationXValidate interface or ProcessorXValidate interface) by writing a xValidate method that returns String array
For operations, use the xValidate(Context) method. For processors, use the xValidate(transitionContext, transitionName) method. It is required to define the class name that is implementing the cross validation in the processor definition.
The result of the cross-validation method is an array of Strings (messages), which are stored in the operation context under the key of 'dse_ErrorMessages'. This context will be used later during the dynamic creation of the HTML.
Following is a cross-validation definition example for an operation: