JSF: Lesson – 6: Validating User Input in JSF #Java Short Notes

  • Target: Intermediate level web-developers.
  • Sample application for this article
  • Video Tutorial for this article
  • In web-application development, validating user inputs takes much efforts. JSF has made validations much easier than usual
  • JSF Built-in Validators:
    • validateDoubleRange: Checks that the value provided is a double value. You can also set a minimum and a maximum.
    • validateLongRange: Validates the input to be a long. It also has the optional minimum and maximum parameters.
    • validateLength: Validates the length of a string
    • Without the minimum and the maximum values these validators actually do nothing
  • You can also enforce a value as follows. If no value is provided, an error message is displayed
    
    
  • You can also create your own custom validator that should implement javax.faces.validator.Validator interface.
  • You have to implement the validate() method: validate(FacesContext arg0, UIComponent arg1, Object arg2) throws ValidatorException
  • In the error condition, you should throw ValidatorException from the validate method
  • Then you need to register the custom validator in the faces-config.xml file using a id as follows:
        currency.validator    net.justetc.jsf.CurrencyValidator  
  • From your JSP, you can refer to the validator as follows:
  •                                         

From: http://sitestree.com/?p=4997
Categories:Java Short Notes
Tags:
Post Data:2012-05-25 08:43:55

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada