Runtime components : Channels components : HTML Channel : Tasks : Performing validation
  
Performing validation
After Completing This Task: This section describes how to perform data field syntatic validation, data field semantic validation, and cross-field validation.
See
Performing data field validation
Implementing semantic validation
Performing cross-field validation
Creating a dynamic transition context
See also
Tasks
Performing data 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
<dse:error dataName="amount"/> in transfer.jsp
See also
Performing validation
Implementing semantic validation
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
<dse:error dataName="amount"/> in transfer.jsp
See also
Performing validation
Performing cross-field validation
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:
<operation id=transferFunds context= transferFundsCtx
xValidation=com.ibm.btt.samples.html.transferFundsXVal>
Following is a cross-validation definition example for a process:
<processor id=financialInfo context=financialInfoCtx
xValidation=com.ibm.btt.samples.html.FinancialInfoXVal>
Following is an example of the data type definitions file:
<?xml version="1.0"?>
<dsetype.xml>
<!-- DSETYPE.XML-->
<!-- If property descriptors do not have "refType"s, they will point -->
<!-- to the type with thesame first name as themselves. -->
<!-- Exception is Property descriptors with id=typeDefault. They do -->
<!-- not need "refType" because they will point to the enclosing type. -->
<type id="String" implClass="com.ibm.btt.base.DataField">
<StringDescriptor id="typeDefault">
<stringConverter convTypes="default,host"
implClass="com.ibm.btt.base.types.ext.StringConverter"/>
</StringDescriptor>
</type>
<type id="Date" implClass="com.ibm.btt.base.DataField">
<DateDescriptor id="typeDefault" refType="Date">
<dateConverter convTypes="default"
implClass="com.ibm.btt.base.types.ext.DateConverter"
pattern="ddMmmyyy"/>
<dateConverter convTypes="xml"
implClass="com.ibm.btt.base.types.ext.DateConverter"
pattern="ddmmyy"/>
<dateValidator implClass="com.ibm.btt.base.types.ext.DateValidator"
mask="ddMmmyyyy"/>
</DateDescriptor>
</type>
<type id="AccountList" implClass="com.ibm.btt.base.IndexedCollection">
<ICollDescriptor id="typeDefault" refType="AccountList" size="0"/>
<IntegerDescriptor id="account number" refType="String"/>
</type>
<type id="Customer" implClass="com.ibm.btt.base.KeyedCollection"
keyBuilder="mySolemTest.FundsTransferKeyBuilder">
<KCollDescriptor id="typeDefault" refType="Customer"/>
<StringDescriptor id="customer name" refType="String" initialValue="Ralph"/>
<KCollDescriptor id="accounts" refType="AccountList" size="3"
description="list of accounts"/>
</type>
<type id="FundsTransfer" implClass="com.ibm.btt.base.KeyedCollection">
<KCollDescriptor id="typeDefault" refType="FundsTransfer"/>
<StringDescriptor id="accountFrom" refType="String" initialValue="2345"/>
<StringDescriptor id="accountTo" refType="String" initialValue="678589"/>
<DateDescriptor id="transactionDate" refType="Date">
<dateConverter convTypes="xml"
implClass="com.ibm.btt.base.types.ext.DateConverter" pattern="Mmmyy"/>
</DateDescriptor>
</type>
<type id="Float" implClass=com.ibm.btt.base.DataField">
<FloatDescriptor id="typeDefault">
<floatConverter convTypes="default"
implClass="com.ibm.btt.base.types.ext.FloatConverter"/>
<floatValidator implClass="com.ibm.btt.base.types.ext.FloatValidator"/>
</FloatDescriptor>
</type>
<type id="AccountTransferData" implClass="com.ibm.btt.base.KeyedCollection">
<KCollDescriptor id="typeDefault" refType="accountTransferData"/>
<StringDescriptor id="acctFrom" refType="String"/>
<StringDescriptor id="acctTo" refType="String"/>
<FloatDescriptor id="amount" refType="Float"/>
<StringDescriptor id="acctFromBalance" refType="String"/>
<StringDescriptor id="acctToBalance" refType="String"/>
</type>
</dsetype.xml>
Following is a context definition that refers to the AccountTransferData type definition:
<!---------------------------------------------------------------------------->
<! Account Transfer Operation Context... >
<!---------------------------------------------------------------------------->
<context id="AccountTransferCtx" type="oper" parent="htmlPageCtx">
<refType refId="AccountTransferData">
</refType>
<refService refId="theJournal" alias="Journal" type="cs"/>
<refService refId="theHost" alias="host" type="cs"/>
</context>
For an example of cross-field validation for simple operations, see the following in the HTML Sample Application:
accountTransferOp.xml (see the xVal attribute)
com.ibm.btt.samples.html.AccountTransferXVal class
<dse:valErrors renderMode="combo" /> in transfer.jsp
For an example of cross-field validation for navigation processes, see the following in the HTML Sample Application:
creditCardsProc.xml (see the xValidation attribute)
com.ibm.btt.samples.html.CreditCardApplXVal class
<dse:form action="/DSE_HtmlSampleAppl/Request" errorPage="creditApplMissingInfo.jsp" nextEventName="history"> in creditCardsWellcome.jsp
creditApplMissingInfo.jsp
See also
Performing validation
Creating a dynamic transition context
For an example of how to create a dynamic transition context from within a JSP, see the following in the HTML Sample Application:
cancelConfirmation.jsp
cancelConfirmationState in financialInfoProc.xml (note that the “Cancel” transition does not define any context)
See also
Performing validation