Step 1. Configure the TroubleTicketSystemWebClient  project for JSF

Time to complete this step: 10 minutes

JavaServer Faces (JSF) technology simplifies building user interfaces for JavaServer applications. Developers can quickly and easily build web applications by assembling reusable UI components in a page, connecting these components to an application data source / model, and wiring client-generated events to server-side event handlers. The user interface code runs on the server, responding to events generated on the client. This allows the application developer to focus on application code.

Oracle Enterprise Pack for Eclipse (OEPE) extends Eclipse and the Web Tools Platform (WTP) to support the development of JSF 1.1 and 1.2 applications.

In this tutorial, you will create JSF client pages that submit new ticket requests using the TroubleTicketSystem Web Service clients.

In this step, you will configure the dynamic web project called TroubleTicketSystemWebClient that is enabled with the WebService Client facet.  

Before you start the tutorial steps, download the resources.zip and unzip it. The extracted resources folder has a set of JSP pages for web service invocation.

You will perform following tasks in this step:


Configure the dynamic web project TroubleTicketSystemWebClient for JSF 

  1. In Project Explorer view, right-click the TroubleTicketSystemWebClient project and select Properties from the context menu. This will open the Properties dialog as shown below. Select the Project Facets item in the left panel. That shows list of selected project facets as configured for the  TroubleTicketSystemWebClient project. 
  2. Select JavaServer Faces (verion 1.2) from the Project Facets list. That enables a link stating Further configuration required..

  3. Click Further configuration required... link. This will open the Modify Faceted Project dialog to configure  JSF capabilities for TroubleTicketSystemWebClient project. WebLogic offers shared library for J2EE projects.
  4. A WebLogic Shared Library is an Enterprise Application Archive, a stand-alone EJB, a Web Application module, or a JAR file that is registered with the WebLogic Server as a shared library. The library resources can be shared between multiple applications, alleviating the need to have duplicate copies of the resources in each application. You can click the Manage WebLogic Shared Libraries... link to review or further manage it. That opens Preferences dialog for WebLogic Shared Libraries. If required, you can also edit a specific library.
  5. Note: For this tutorial, we are not going to edit any library. The JSF (version 1.2/1.2.3.2) shared library has SunRI for JSF 1.2 specifications. For this tutorial, we will use the JSF (version 1.2/1.2.3.2) shared library.

      

  6. The Modify Faceted Project dialog for JSF capabilities also provides options for the JSF configuration file.

    1. The JSF Configuration File option describes the location for the faces-config.xml file. 
    2. The JSF Servlet Name and JSF Servlet Classname describes the mapping to the javax.faces.webapp.FacesServlet class.
    3. The URL Mapping Patterns describes the prefix mapping to identify a JSP page as having JavaServer Faces components. 

  7. Click OK in the Modify Faceted Project dialog.
  8. Click OK in the Properties dialog for the TroubleTicketSystemWebClient project. That completes the JavaServer Faces configuration for the TroubleTicketSystemWebClient project and generates the following artifacts.
    • The JSF configuration file ( faces-config.xml ) under the TroubleTicketSystemWebClient/WebContent/WEB-INF folder.
    • A resource bundle application.properties file under the TroubleTicketSystemWebClient/src folder. 
    • Also, a separate faces-config node will be enabled that describes various configuration components of faces-config.xml.

  9. Note that as you have added the JavaServer Faces facet to the web project  TroubleTicketSystemWebClient, the project's web.xml file will be updated to include servlet mapping to the  javax.faces.webapp.FacesServlet instance. The  FacesServlet instance accepts incoming requests, passes them to the life cycle for processing, and initializes resources. The URL mapping to  FacesServlet uses prefix mapping to identify any JSP page (as having JavaServer Faces components) that starts with  faces. Open the web.xml file and review the configuration.

    ...
    ...
      <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
      </servlet-mapping>

    </web-app>



 

Configure resource bundle and locale

During developing the internationalized application, sometimes it is necessary to view the JSP pages in the different languages to fix the localization and web design issues related to internationalization. You will configure the application to support english and french locales.

  1. Open the  TroubleTicketSystemWebClient > WebContent > WEB-INF > faces-config.xml.
  2. That opens the faces-config.xml with the multi-page Faces-Config Editor.

  3. Switch to the Source tab. You can notice that the JavaServer Faces configuration file has set resources.application as the message bundle and locale set to en (English)

  4. Copy the  application.properties and  application_fr.properties file from the extracted  resources folder to the TroubleTicketSystemWebClient/src/resources folder. These application_xx.properties files represent application resource bundles with messages in English and French languages. You will be prompted to overwrite the existing  application.properties file, click Yes.
  5. Switch to the Others tab. Expand the Locale Config group.

  6. Click the Add button and select the fr locale from the list.

  7. Click OK. That configures fr (French) as another supported locale for the application. The default locale is en (English).
  8. Save the faces-config.xml file.

 

Create Java packages and import resources

  1. Copy the  css folder from the extracted  resources folder to the TroubleTicketSystemWebClient/WebContent folder.
  2. In the Project Explorer view, right click the TroubleTicketSystemWebClient > Java Resources > src folder and choose New > Package. Enter the package name com.oracle.ticketsystem.jsf.beans and click Finish. Under this package, you will create JSF managed bean classes. 

     

  3. This creates a new Java package com.oracle.ticketsystem.jsf.beans. Similarly, create another Java package com.oracle.ticketsystem.util.
  4. Copy the  MessageFactory.java and  WebServiceClientFactory.java files from the extracted  resources folder to the com.oracle.ticketsystem.util package. 
    • The MessageFactory class is a helper class that retrieves messages from the application resource bundle.
    • The WebServiceClientFactory class is a factory for providing the Ticket System web service client references.

      public class WebServiceClientFactory {

       public static TicketWebService ticketService;
       public static ProductWebService productService;
       
       public static TicketWebService getTicketWebService() {
         if(ticketService == null) {
           TicketWebServiceService ticketWebServiceService = new TicketWebServiceService();
           ticketService = ticketWebServiceService.getTicketWebServicePort();
         }
         return ticketService;
       }
       
       public static ProductWebService getProductWebService() {
        if(productService == null) {
          ProductWebServiceService productWebServiceService = new ProductWebServiceService();
          productService = productWebServiceService.getProductWebServicePort();
        }
        return productService;
       }
       
      }



      


Click the arrow below to navigate through the tutorial: