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

5. Running the application

In this step, we will create server configurations and deploy and run the JSF application.

5.1. Add Context Listener and update application configuration

Our application uses the DataStoreBean class which is available in application scope. You have been provided a Servlet Context Listener called ContextListener which registers an instance of DataStoreBean to ServletContext at application start up.

5.1.1. Import the ContextListener class

Create a new package called listeners and copy the file ContextListener.java from the folder workshop-JSF-tutorial/web/Resources folder to the listeners package.

5.1.2. Add context listener to web.xml file

  1. Open the web.xml file. In the Web Application Deployment Descriptor Design Editor right-click the Listeners node and select New Listener. Choose the listener type ContextListener as shown below:


  2. This will add a listener element for the ContextListener class.

  3. Save the web.xml file and review the web application configuration elements.


  4. The servlet javax.faces.webapp.FacesServlet is configured to receive HTTP requests with URL-pattern .jsf

    The web.xml file includes tag library mappings to support JSP tag libraries.

5.2. Create Server Configurations

Workshop has the ability to run and debug applications on most of the popular web containers in use today. Before you can run this sample application, you must have a server installed.

  1. Click on the Servers tab. If the Servers view tab is not displayed, click Window > Open Perspective > Workshop to display it (or click Window > Show Views > Other then expand Server, click on Servers and click OK).
  2. Right click on the Servers tab and choose New > Server.

  3. Choose the type of server that you have installed. Click Next.

  4. The screen that displays next depends on the type of server that you have chosen. This screen allows you to configure your server. Choose the server settings and click Next to continue.

  5. Select the project name in the left pane and click Add to move it to the right pane. Click Finish.
  6. The new server is displayed in the Servers view.

5.4. Run the application

In the Server View, right-click Tomcat configuration and click Start. Once the server starts successfully, the default web browser comes up. Enter the URL http://localhost:8080/pages/register.jsf in the address field of the browser.

The application first performs the data validation based on the rules defined for form fields. If you try to submit the data without filling in the Password field, you will get an error response.

If you enter a User ID of less than 4 characters and Password less than 1000, then you will get an error response.

On successful registration, the user will be forwarded to the home.jsp page.

 

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

 

Skip navigation bar   Back to Top