Wednesday, May 15, 2013

Simple number validation in JSF

There are many ready validator in JSF, eg. <f:validateLongRange />, <f:validateDoubleRange />, <f:validateRegex />, etc.
for more information about JSF validator, please refer here.

to validate number value, we can use the ready made JSF validator, that is <f:validateLongRange /> and <f:validateDoubleRange />

Sample code:
private String longValue;
// getter & setter for longValue

private String doubleValue;
// getter & setter for doubleValue;

jsp or xhtml
<h:inputText value="#{bean.longValue}" id="longnumber"
    validatorMessage="invalid long number">
    <f:validateLongRange />
<p:message for="longnumber" id="message1"/>

<br />

<h:inputText value="#{bean.doubleValue}" id="doublenumber"
    validatorMessage="invalid double number">
    <f:validateDoubleRange />
<p:message for="doublenumber" id="message2"/>

validating long number and double number

Other input validation example in JSF:
  - Credit Card
  - Email
  - Number, with regular expression


No comments:

Post a Comment


Related Posts Plugin for WordPress, Blogger...