Group Discounts available for 3+ students and Corporate Clients

Developing JSF2 Validations Application


Sid= student id

Sname-student name

Saddr-student address

Semail-student email

Smobile-student mobile

Button=add student

Javax.faces. validator.  Regexvalidator. Not.matched- detail

Value must be provided in “{o}” format

Sid-validation-msg=student id must be started with dss





<meta http-equal=”Refresh” context=”2; url=http://local host:1010/ Jsf2validations app/student add form.dss”>



<h1>Application is loading </h1>




Student add form.jsp

<%@laglib prefix=”f”url=

<%@                            ”h”



<h1>soft pvt ltd</h1>

<h2>student add form</h2>


<h:panel Grid columns=”3” >

<h:output text value=”#{msg.sid}”/>

<h: input text id=”sid” value =”#. { student bean.sid}”

Required=”true” required message=student IN is required”>

<f:validator validator In=”sid validator”/>

</h: input text>

<h:message for=”sid”/>

<h:output text value=”#{msg. sname}”/>

<h: input text id=”s name” value =”#. { student bean. name }”

Required=”true” required message=student name is required”>

</h:input text>

<h:message for=”sname”/>

<h:output text value=”#{msg. saddr}”/>

<h: input text id=”s addr” value =”#. { student bean. naddr }”

Required=”true” required message=”student address is required”>

<h: message for=”saddr”/>

<h:output text value=”#{msg. semail}”/>

<h: input text id=”s email” value =”#. { student bean. semail }”

Required=”true” required message=”student email is required”>

<h: message for=”semail”/>

<h:output text value=”#{msg. s mobile}”/>

<h: input text id=”s mobile” value =”#. { student bean. S mobile }”

Required=”true” required message=”student mobile required”>

<f:validate Ragex pattern=”/d{2}-/d{10}$”/>

</h:input text>

<h: message for=”smobile”/>

<h:command button value=”#{msg. button}”action=#{student bean. add}”/>

</h:panel Grid>







<%@laglib prefix=”f”prefix=”h”



<f:view><h1>student Registration success</h1></fiview>



Package com. soft;

Public class student bean{

Private string sid;

Private string sname;

Private string saddres;

Private string semail;

Private string smobile;

Private string saddres;

//provide setter()&getter()

Public string add(){






Package com.durgasoft;

Import java.util.x;

Import java. faces. application. applicaiton;

Import java. faces. application. facesnessage;

Import java. faces. Component.uicomponent;

Import java. faces. Context.faces context;

Import java. faces. Validator, validator;

Import java. faces. Validator, validator exception;

Public class SID validator implements validator{

Public Void validate(faces context tc,UI Component ue,object val)

Throws validate exception{

String sid=(string)val;


Faces message fm=new faces message();

Application application=fc.get application();

String prop-path=application. Get message bundle();

Resource bundle rb=resource bundle. get bundle(prop-path);

Strubg err-msg=rb.get string(“sid-validation-msg”);

Fm.set detail.(err-msg);

Throw new validate exception (fm);








<managed-bean-name>student bean</managed-bean-name>



<navigation rule >

<from-view-id>/student add from.jsp</  >

<navigation case >

<from-outcome>success</    >

<to-view-id>/success.jsp</    >

</navigation case >

</navigation rule>


<validator-id>sid validator</   >

<validator-class>com. soft.SID Validator</   >




<base-name>abc</  >

<var>msg</  >


<message- bundle >abc</message- bundle >

</application >

</faces-config >





Step2 –  Configure user- defined converter class in faces – config.xml file

<faces- config>



<converter -id>converter logical name</  >

<converter-class>fully qualified converter class</  >






Use. User- defined converter in both i/p and o/p UI Component

To use converter in i/p and o/p UI Components wl have to use the following tag

<f:converter conver ID=”–”/>

Where “converter Id” attribute will take logical name of the converter class which we provided in

[for example appl n on JSF data table, GUI Components & converters refer hand out given o n16 th Nov 2013]



“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at, we will update the article in 24 hours.”

0 Responses on Developing JSF2 Validations Application"

Leave a Message

Your email address will not be published. Required fields are marked *


Please Enter Your Details and Query.
Three + 6