This section describes how to perform data field syntactic 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 BTTBasePortlet. The startup operation might define its typed data elements with the same validators.
To implement semantic validation for an operation, perform the following procedure:
Here is an example of how semantic data field validation works on a data field.
The following is the source code in the sample Java™ file.
public class SampleXVal extends BTTXValidate implements OperationXValidate { public void validate(String fullyQualifiedName, DataField df, Context ctxt) throws DSETypeException { if (fullyQualifiedName.equals("amount")) { if (Double.valueOf((String)df.getValue()).doubleValue() > 20000) { throw new DSETypeException ( DSETypeException.harmless, "VALID101", "Cannot_transfer_such_amount" ); } if (Double.valueOf((String)df.getValue()).doubleValue() < 1000) { throw new DSETypeException ( DSETypeException.harmless, "VALID101", "Cannot_transfer_such_amount" ); } } return; } }
<btt:text dataName="amount" error="yes" size="10" maxLength="10"/> <btt:error dataName="amount"/>
Each business operation is responsible for cross-validating the data by performing the following procedure:
For operations, use the xValidate(Context) method. It is required to define the class name that is implementing the cross validation in the operation definition.
The result of the cross-validation method is an array of strings (messages), which are stored in the operation context under the "dse_ErrorMessages" key. This context is used later during the dynamic creation of the HTML.
Here is a cross-validation definition example for an operation:
<operation id="transfer" context="transferCtx" xValidation="test.transferXVal"/>
Here is the corresponding Java source:
public class SampleXVal extends BTTXValidate implements OperationXValidate { public String[] xValidate ( Context ctx ) { String facct = getStringValue ( ctx, "acctFrom" ); String tacct = getStringValue ( ctx, "acctTo" ); Vector verrs = new Vector ( ); if ((facct.length ( ) > 0) && (facct.equals ( tacct ))) { verrs.addElement ("The_source_account_and_the"); } return asStringArray ( verrs ); } }