Only the Text and Password widgets need the validator. There are two types of validator, Before-Validator and After-Validator. See the following table for details:
Widget | Injection | Injection description | Sample in UI.xui |
---|---|---|---|
Text | beforeValidators | When user start to input, beforeValidators will run. If validation failed, the input will be ineffective. | <Text background="240,0,0"> <list Injection="beforeValidators"> <com.ibm.btt.sample.xui.AccNumberValidator/> </list> </Text> |
afterValidators | When user input finished and lost the focus status for the text widget, the afterValidators will run. If validation failed, the error system will display the information about it. | <Text background="240,0,0"> <list Injection="afterValidators"> <com.ibm.btt.sample.xui.AccNumberValidator/> </list> </Text> |
|
Password | beforeValidators | When user input, beforeValidators will run. If validation failed, the input will be ineffective. | <Password background="240,0,0"> <list Injection="beforeValidators"> <com.ibm.btt.sample.xui.AccNumberValidator/> </list> </Password > |
afterValidators | When user input finished and lost the focus status for the text widget, the afterValidators will run. If validation failed, the error system will display the information about it. | <Password background="240,0,0"> <list Injection="afterValidators"> <com.ibm.btt.sample.xui.AccNumberValidator/> </list> </Password > |
Prebuilt Validator
XUI engine also provide some prebuilt validator. See the following table for details:
Validator | Description |
---|---|
AlphaNumericValidator | The input can only be number and alpha. It can be used in afterValidators and beforeValidators; |
NumericValidator | The input can only be number. When the input is not a valid alphabet character, it will be ineffective. It can be used in afterValidators and beforeValidators. |
NumberPatternValidator | The input can only be as the pattern specified. This format of the pattern is ‘##-##-##’. The ‘#’ stands for a number. |
MinLengthValidator | Using this you can specify the minimal length of text input. It's usually used in afterValidators. |
MaxLengthValidator | Using this you can specify the maximum length of text input. It can be used in afterValidators and beforeValidators. |
RegexValidator | The input must match the regex which is specified by the regex property. It's usually used in afterValidators. |
DateValidator | The input can only be date. The format of the Date is specified by the format property. For example “yyyy/MM/dd”. It's usually used in afterValidators. |
EmailAddrValidator | The input can only be the email string. |
To inject this function, you should create your own class.
package DeveloperPackage; public class DeveloperValidator extends com.ibm.btt.rcp.xui.validator .Validator { { setErrorMessage("Developer’s NORMAL Validation Error"); } public String validate(IXUIWidget source, String text) { {// do Developer’s validation logic here. Return null if it passes. } return getErrorMessage(); } }
package DeveloperPackage; public class DeveloperValidatorRE extends com.ibm.btt.rcp.xui.validator . AbstractRegexValidator{ { setErrorMessage("Developer’s REGULARE EXPRESSION Validation Error"); } public String getRegex() {// the returned string express Developer’s validation logic. return “DeveloperRegularExpressionStringLike:[\\da-zA-Z]+[-._+&'])*[\\da-zA-Z]”; }// getRegex }//class
<Text> <list Injection="afterValidators"> <DeveloperPackage.DeveloperValidator/> </list> </Text>
<Text> <list Injection="beforeValidators"> <DeveloperPackage.DeveloperValidator/> </list> </Text>