In general, in JSF based web applications, it we submit a form data to server then container will take from data request parameters data and store in request object, where faces context will take from data from request object and store in component tree as part at “Apply request values” life cycle phase. After getting form data in component tree, faces servlet will store form data from component tree to model object as part of “update model” life cycle phase after getting data in managed bean object, we will use form data in application logic as part of “Invoke application” life cycle phase.
If we check data validity just before submitting form to server then it is called as client side data validations.
To overcome the above problems, we have to go for server side data validations
It we check data validity after strong data in component tree and just before passing data to managed bean object then it is called as server side data validations.
Standard data validations are the data validations provided by ISF frame work predefinetly
Required It is an attribute at each and every input component to check weather data is available or not
NOTE In JSF all the predefined Validator are having their own predefined message provided by JSF at the following location Extract JSF-api.jaràJavaxàfacesàmessage.properties
Javax. faces. component. UI Input. Required ={o}; validations Error value is required
Where<h:message> is used to display a validation message with respect to a particular field <h:message for=”component Id value”/> Eg <h:message for=”uname”/> Where<h:message>tag can be used to display all the validations messages of the respective fields which are available in the current page. e.g <h:output text value=”user name”/> <h:input text id=”u name ”value=”reg bean. U name” required=”true”/> <h:message for=”u name”/> Validate Length
Where minimum attribute will take min length value and maximum attribute will take max length value
Javax. faces. Validator, length Validator, minimum={1}:validation error value is less than allowable minimum of”{0}”
Javax. faces. Validator. Length Validator. maximum=”{1}”: validation error. Value is greater than allowable maximum of “{0}” where{1}will take component name like uname upwd where{0} will take attribute values like ”minimum” and “maximum” on the basis of the validation msg Eg <h:output te:1 value=”password”/> <h:input text id=”upwd” value=#{reg bean. upwd}/required=”true”> <f:validate length minimum=”6”maximum=”15”/> </h:input text> <h:message for=”upwd”/> validate long range This Validator can be used to check wheat here the data or on input field is long data or not and the value is available in the specified range or not. Case1 If the provide value is not long data type then this Validator will display the following validation message javax. faces. Validator. lang range Validator. Type={0}; validation error: value is not at correct type Case2 If the provide value is not long data, it we provides only “minimum” attribute without “maximum” attribute and it the provided value in the input field is less than the specified “minimum” attribute value then this Validator will display the following validation message Javax. faces. Validator. Lang range Validator. Minimum= {1}: validation error: value is greater than allowable minimum of”{0}” Case3 It the provided data is long data, it we provide only ”maximum” attribute in<f:validate long range> Validator and if the provided value in input field is greater than ’maximum’ attribute then this Validator will display the following validation message. Javax. faces. validate. Lang range Validator. Maximum={1}; validation error: value is greater than allowable maximum of “{0}” Case4 It the provided value is lang data, it we provided both “minimum” and “maximum” attribute in <f:validate lang range>valid after and if the provided value in put field is less than the provided “minimum” attribute value are greater than the “maximum” attribute value then this Validator will display the following message. Javax.faces. validatore. Long range validatore. Not- in- range ={2}; validation error: specified attribute is not bet n the expected values of {0} and{1} Eg <h:output text value=”user age”/> <h:input text id=”age” value=”#{reg bean. uage}” required=”true”> <f:validate lang range minimum=”18”maximum=”30”> </h: input text > <h: message for=”uage” > Validate double range This Validator can be used to check whether the data on an input field is double or not and the provided value is a variables within the specified range or not <f:validate double range minimum=”--”maximum=”--”> Where ”minimum” and ”maximum” attributes can be used to provided minimum and maximum values. Case1 If the provided data on the respective field is not double data then this Validator will display the following error msg. Javax. faces. Validator. double range Validator. type={0}:validation error: value is not of the correct type. Case2 It the provided data is double data, It we provide only ”minimum” attribute without “maximum” attribute In<f:validator double range>Validator and it the provided value is less than the specified minimum value then this validator will display the following validation msg Javax.faces. validator, double range Validator MINIMUM{1}:validation error:value is less then allowable minimum of “{0}” Case3 It the provided data is double data, It we provide only ” maximum” attribute without “minimum ” attribute In<f:validator double range>Validator and it the provided value is greater than the specified maxim value then this validator will display this validation msg Javax. faces. Validator, double range Validator maximum{1}:validation error: value is greater than allowable maximum of “{1}”validation error: value is greater than allowable maximum of “{1}” Case4 It we provided data is double data, It we provide both attributes In<f:validator double range>validator and it the provided value is less than the specified min value or greater than validation msg. Javax. faces. validatore, double range validator NOT-IN RANGE {2}:validation error: Specified attribute is not bet n the expected values of{0}&{1} Eg <h:output text value=”user salary”/> <h:input text id=”usal” value=#{reg Bean. usal}”required=”true> <f:validator double range minimum=”2500”maximum=”50000”/> </h:input text> <h:message fore=”usal”/>
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.