Magazine
 
JSF

if(loginid.equals(“JavaJazzUp”) &&
pwd.equals(“mypwd”))
{
return “success”;
}
else{
return “fail”;
}
}
}

Description:

In login.jsp file, we have used managed bean’s properties and methods. For this LoginBean bean have been created which is nothing but a simple java file which has properties representing username and password, their setter and getter methods and an extra method to check whether the user is genuine. This method returns “success” if user fills username as “JavaJazzUp” and password as “mypwd” and “fail” if user fills any other.

Working with Configuration file

1. faces-config.xml file:

<?xml version=”1.0"?>
<!DOCTYPE faces-config PUBLIC
“-//Sun Microsystems, Inc.//DTD JavaServer
Faces Config 1.1//EN” “http://java.sun.com/
dtd/web-facesconfig_1_1.dtd”>
<faces-config>
<managed-bean>
<managed-bean-name>LoginBean
</managed-bean-name>
<managed-bean-class>
javajazzup.LoginBean
</managed-bean-class>
<managed-bean-scope>request
</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/login.jsp</from-view-id>
<navigation-case>
<from-action>
#{
LoginBean.CheckValidUser
}
</from-action>

 

<from-outcome>success</from-outcome>
<to-view-id>loginsuccess.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>
#{
LoginBean.CheckValidUser
}
</from-action>
<from-outcome>fail</from-outcome>
<to-view-id>loginfail.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>

In this file, managed bean “LoginBean” in “javajazzup” package has been registered as LoginBean. This is the name, which will be used in every page to access this bean as we did in login.jsp. Navigation rule has also been defined in this file. If CheckValidUser method returns “success” then “loginsuccess.jsp” page is returned and if “fail” then “loginfail.jsp” is returned to the user.

2. web.xml file code:

<?xml version=”1.0"?>
<!DOCTYPE web-app PUBLIC “-//Sun
Microsystems, Inc.//DTD Web Application
2.3//EN” “http://java.sun.com/dtd/webapp_
2_3.dtd”>
<web-app>
<context-param>
<param-name>
javax.faces.STATE_SAVING_METHOD
</param-name>
<param-value>server</param-value>
</context-param>
<!— Faces Servlet —>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet
</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<!— Faces Servlet Mapping —>
<servlet-mapping>

Nov 2007 | Java Jazz Up | 45
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69   Download PDF