7. Adding Other Web Components [Optional]
In this step, you will import the Managed Bean ( LoginBean )
and view ( login.jsp ) to the web application. You will also
define navigation rules for the login.jsp page and run the
application.
7.1. Importing managed bean and view
- Copy the LoginBean.java file from the folder workshop-jsf-tutorial/web/Resources to the beans package.
- Open and review the code of the LoginBean
class. The validate( ) method verifies the
userId and password of the user and returns the logical outcome login
to navigate to the home.jsp page. If, the
userId or password is incorrect, it returns null
to request re-login and shows the error message.
- Configure LoginBean as Managed Bean in workshop-jsf-tutorial/web/WEB-INF/config/faces-config.xml
file, as shown in the image below. (Open faces-config.xml and click the Faces
Config tab in the editor, if necessary. )

- The scope of LoginBean is request. Save the faces-config.xml
file.
- Add the following key-value pairs to the workshop-jsf-tutorial/web/WEB-INF/src/java/resources/application.properties
file. You can also copy it from the file workshop-jsf-tutorial/web/Typing_Aid/application_properties_3.txt
# -- login page --
loginPageTitle=Login to Workshop...
loginFormHeader=Member Login
login_NewUser=New User
login_SignUp=Sign Up
invalidPassword=Please provide correct password for userId: {0}
invalidUserId=Please provide correct userId |
- Save the application.properties file.
- Copy the login.jsp.txt file from the workshop-jsf-tutorial/web/Resources folder to the pages folder and rename it to login.jsp.
7.2. Defining the Navigation Rule for login.jsp
Note that the LoginBean.validate method returns login to navigate to home.jsp page.
- Using the Navigation view of faces-config.xml file
define the navigation rule for the login.jsp page.

- Define new navigation case for the navigation rule /pages/login.jsp
page, as shown in the images below.


- Save the faces-config.xml file.
7.3. Running the application
- Right click on the login.jsp file in the AppXplorer
view. Select Run As > Run on Server.
- If necessary, in the web browser enter the URL
http://localhost:7001/pages/login.jsf.
- Click the Submit link and login with
the userId james.
- Try logging in without a password and observe the error message.
- Login with invalid password value 1006 for userId james and
observe the error message.
- When you login with the correct userId and password (james / 1007), you
will be navigated to home.jsp page.
- Stop the server.
Click one of the following arrows to navigate through the tutorial:
Still need help? Post a question on the Workshop
newsgroup.