Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

JSF Validation In Login Application

This section gives you the best approach for the login application. You have learnt about the login application without validating the application. But in this section you will learn how to validate a form in JSF using it's tags.


JSF Tutorials: Easy steps to learn JSF Java Server Faces (JSF) Tutorials What is JSF Mojarra? JSF Life Cycle JSF Examples JSF Tutorial For Beginners Roseindia JSF Tutorial JSF core Tag Reference JSF internationalization example Tomahawk selectOneCountry tag RCFaces About Hibernate, Spring and JSF Integration Tutorial Creating Login Page In JSF using NetBeans JSF Hello World Declaring the Bean class in the faces-config.xml file Creating a Web Application with the JSF Framework Binding the Form Elements With the Bean Properties Adding Navigation in JSF Application Binding Component Instance to a Bean Property Tomahawk validateEqual tag Tomahawk validateEmail tag Tomahawk validateCreditCard tag Tomahawk selectOneListbox tag Tomahawk selectManyListbox tag Tomahawk selectManyCheckbox tag Tomahawk selectBooleanCheckbox tag Tomahawk saveState tag Tomahawk popup tag Tomahawk inputCalendar tag Tomahawk htmlTag tag Tomahawk graphicImage tag Tomahawk documentHead tag Tomahawk documentBody tag Tomahawk document tag Tomahawk column tag DataBase Connectivity with MySql in Visual Web JSF Application Using Net Beans IDE Retrieve Image in JSF From MySQL Table Using NetBeans IDE JSF Training Java Sever Faces 1.2 - JSF 1.2 Display Data from Database in JSF Application Business Objects of Business Logic tier Setup MySQL Database Working with Database through JDBC Working with JavaScript & CSS Referencing a Localized Message Referencing Resource Bundle from a Page Binding Component Value to an Implicit Object Phase Listener Value Change Event Listener Action Event Listener
<%@ page contentType="text/html"%>
<%@ taglib uri="" prefix="f"%>
<%@ taglib uri="" prefix="h"%>

<head><title>JSF Simple Login Example</title></head>

<td><h:outputText value="Enter
Login ID: " /></td>
<td><h:inputText id="loginname"
value="#{SimpleLogin.loginname}" required="true" />
<font color="#FF0000">
<h:message for="loginname"/></font></td>
<td><h:outputText value="Enter Password:
" /></td>
<td><h:inputSecret id="password" value="
#{SimpleLogin.password}" required="true" />
<font color="#FF0000"><h:message for="
<td><h:commandButton value="Login" action
="#{SimpleLogin.CheckValidUser}" /></td>

Here is the code for the resultforfail.jsp file:

Login Failed!

Here is the code for the resultforsuccess.jsp file:

Login Successful!

Here is the code for the Backing Bean file:

package roseindia;

public class SimpleLogin{
	String loginname;
	String password;

	public SimpleLogin(){}

	public String getLoginname(){
		return loginname;

	public void setLoginname(String loginname){
		this.loginname = loginname;

	public String getPassword(){
		return password;

	public void setPassword(String password){
		this.password = password;

	public String CheckValidUser(){
&& password.equals(
"chand")){ System.out.println("chandan"); return "success"; } else{ return "fail"; } } }

faces-config.xml file code:

<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, 
Inc.//DTD JavaServer Faces Config 1.1//EN"


web.xml file code:

<?xml version="1.0"?> 
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 
2.3//EN" "">


    <!-- Faces Servlet -->
        <servlet-name>Faces Servlet</servlet-name>
        <load-on-startup> 1 </load-on-startup>

	<!-- Faces Servlet Mapping -->
        <servlet-name>Faces Servlet</servlet-name>

Download This Complete Application.


Share on Google+Share on Google+

JSF Validation In Login Application

Posted on: February 26, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: JSF Validation In Login Application   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image