JSF Validators are used by other JWL components when performing field validation, input assist and managing client-side data.
<script> hX_5.addConverter("1", new hX_5.NumberConverter("strict:1", "pattern:##", "locale:,.%‰-€")); hX_5.addValidator("2", new hX_5.NumberValidator("required:true", "minimum-bound:18", "maximum-bound:21")); </script>
<script> var c = hX_5.getConverterById("1"); var v = hX_5.getValidatorById("2"); var x = document.getElementById("TestField"); if (c!=null && v!= null && x!=null) { var n = c.stringToValue(x.value); if (n!=null) { if (v.validate(n)) { alert ("Number is OK"); } else { alert ("Number not valid: " + v.lastError()); } } else { alert ("Not a number: " + c.lastError()); } } </script>
<h:inputText styleClass="inputText" id="text1" size="6" value="#{myBean.myBigDecimal01}"> <f:convertNumber pattern="##0.0"/> <hx:inputHelperSpinner delta="0.1"/> <hx:inputHelperAssist validation="true" errorClass="inputText_Error"/> <f:validateDoubleRange minimum="-100.0" maximum="100.0"></f:validateDoubleRange> </h:inputText>
<script> var vID = hX_5.getBehaviorById("form1:text1", "validate", "onblur").getAttribute("validator"); var vld = hX_5.getValidatorById(vID); </script>
id |
The ID to be assigned to this validator. The ID must be unique across all created validators within the page (or portal). Any string value may be used as the ID. |
validatorName |
The name of the JSF validator. See below for the list of validators. |
attributes |
Comma separated list of attributes where each attribute is a quoted string consisting of the attribute name and value separated by a colon, for example "label:MyLabel". |
To get a validator object:
id |
The ID to be assigned to this validator. The ID must be unique across all created validators within the page (or portal). Any string value may be used as the ID. |
To validate a value:
vld |
A validator object. |
value |
A JavaScript object of the type of the converter (Number, Date/Time or String) |
cvt |
A converter object |
returns |
A JavaScript object of the type of the converter (Number, DateTime or String). If the conversion cannot be done, null is returned and lastError is set. |
To retrieve information about why the last validation failed:
var x = vld.lastError();
vld |
A validator object. |
returns |
A JavaScript object of the type of the converter (Number, DateTime or String). If the conversion cannot be done, null is returned and lastError is set. |
To change an attribute of a validator:
vld |
A validator object. |
arg |
A JSF attribute/value string. |
To get an attribute of a validator:
vld |
A validator object. |
argname |
A string containing the name of the attribute. |
returns |
A JavaScript object of the type of the converter (Number, DateTime or String). If the conversion cannot be done, null is returned and lastError is set. |
Validator |
Description |
---|---|
NumberValidator | Validate a string containing a Java-formatted number or a JavaScript number object |
DateValidator | Validate a string containing a Java-formatted date or a JavaScript date object |
StringValidator | Validate a string containing a Java-formatted masked string or a JavaScript string |