Previous Next vertical dots separating previous/next from contents/index/pdf

9. Adding other web components [Optional]

In this step, you can import the Managed Bean ( LoginBean ) and view ( login.jsp ) to the web application. Define Navigation rule for the login.jsp page and run the application.

9.1. Importing managed bean and view

  1. Copy the LoginBean.java file from the folder workshop-JSF-tutorial/web/Resources to the beans package.
  2. Open and review the code of LoginBean class. The validate( ) method verifies the userId and password of user and returns logical outcome login to navigate to the home.jsp page. If, the userId or password is incorrect then returns null to request to re-login and shows the error message.
  3. Configure LoginBean as Managed Bean in faces-config.xml file.
  4. The scope of LoginBean is request . Save the faces-config.xml file.
  5. Add following lines of key-value pairs in application.properties file. You can also copy it from the file workshop-JSF-tutorial/web/Typing_Aid/application_properties_3.txt
  6. # -- 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
  7. Save the application.properties file.
  8. Copy the login.jsp.txt file from the workshop-JSF-tutorial/web/Resources folder to the pages folder and rename it to login.jsp.

9.2. Defining the Navigation Rule for login.jsp

Note that the LoginBean.validate method returns login to navigate to home.jsp page.

  1. Using the Navigation view of faces-config.xml file define the navigation rule for login.jsp page.
  2. Define new navigation case for the navigation rule /pages/login.jsp page.

  3. Save the faces-config.xml file.

9.3. Running the application

  1. Right click on the login.jsp file in the AppXplorer view. Click Run As > Run on Server.
  2. Click Finish to start the server and open the login.jsp page.

  3. Click the Submit link and register with the userId ricky.
  4. Try logging in without a password and observe the error message.
  5. Login with invalid password value 1234 for userId ricky and observe the error message.
  6. With correct userId and password, you will be navigated to home.jsp page.

  7. Stop the server.

Click one of the following arrows to navigate through the tutorial:

 

Skip navigation bar   Back to Top