JSF2 Validations Application

17 September, 2018

Related Blogs

Screenshot_21     Abc. Properties Sid=student Id Sname=student name Saddre=student address Semail=student email Smobilel=student mobile Button=add student Javax. faces. validator. Regix validator. NOT.MATCHED-Detail= value must be provided in “{0}”format Sid-validation-msg=student id must be started with Dss   Index.html <html> <head> <meta http-equiv=”Refresh” context=”2;Ural=http://local host:1010/Jsf2 validations app/student add form .dss”> </head> <body> <h1>application is loading</h1> </ body > </html>   Student add form.jsp <%@loglib prefix= ”f”url= <%@                            ”h” <html> </f:view> <h1> soft pvt ltd</h1> <h2>student add form</h2> <h:form> <h:panel Grid column=”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 Id=”sid validator”/> </h:input text> <h: message for=”sid”/> <h:output text value=”#{msg. sname}”/> <h:input text id=”sname” value=”#{student}” required=”true ” required message= “student name is required”> </h:input text> <h: message for=”s name”/> <h:output text value=”#{msg. saddr}”/> <h:input text id=”saddr” value=”#{student Bean. saddr }” required=”true ” required message= “student address is required”> <h: message for=”saddr”/> <h:output text value=”#{msg. semail}”/> <h:input text id=”semail” value=”#{student Bean. semail }” required=”true ” required message= “student email is required”> </h:input text> <h: message for=”semail”/> <h:output text value=”#{msg. smobile}”/> <h:input text id=”smobile” value=”#{student Bean. smobile}” required=”true ” required message= “student mobile is required”> <f:validate range xpattern=”/d{2}-/d{10}$”/> </h:input text> <h: message for=”smobile”/> <h: command button value=”#{msg. button}”action=”#{student bean. add }”/> </h:parel Grid> </h:from> </f:view> </ body > </html>   Success.JSP <%@Loglib prefix=”f” prefix=”h” <html> </body > </f:view><h1 >student registration success</h1 ></fiview > </body > </html> <body > <f:view> <h1>Registration success</h1> </f:view> </body > </html>   Registration Package com. durga soft Public class Regiatration bean{ Private strin eid; Private strin ename; Private strin eaddre; Private strin eemail; Private strin emobile; //provide setter()&getter() Public string registration(){ Return ”success”; }   Email Package com. soft; Import java. Util. iterator; Import java. Util. resource bundle; Import java. Faces. application. application; Import java. Faces. application. application message; Import java. Faces. component. UI Component; Import java. Faces. content. faces context; Import java. Faces. validator. validator; Import java. Faces. validator. Validator exception; Public class email validate implements validate{ Public void validator(faces context)fe, UI Component we, object value)throws  validator exception{ String email=(string)value; If(email. contains(“@”)){ Application application=fe.get application(); String prp-file=application .get message bundle(); Resource bundle bundle=resource bundle. get bundle(pre-file); String err-msg=bundle. Get string(“email- validator”); Faces message fm= new faces message(); Fm.set detail(err-msg); Throw new validator exception(fm); } } }   Faces-config.xml <Faces-config> ----- ----XSD <managed. bean> <managed. Bean-name>studentBean</managed. Bean-name> <managed. Bean-class>com. soft. registration bean <managed. Bean-scope>session</     > </managed. Bean> <navigation-rule> <from-view- id>/employee from.jsp</> <navigation-case> <from-outcome >success </ > <to-view-id>/success.jsp</ > </navigation-rule> <validator> < validator -id>email-validator</  > <validator-class>com.soft.SIDValidator</> </validator> <application> <resource-bundle> <base-name>abc</b> <var>msg<var> </resource-bundle> <message-bundle>abc</ message-bundle> </application> </faces-config>    
About Author


Author Bio

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 .