< Previous | Next >

Lesson 3: Create an EGL service client

The next step is to create a client project to use the service. While the client you create in this tutorial is in the same workspace, you can imagine that it is in a completely separate location or on a different platform. Since services and clients do not need to be written in the same code language, you can also imagine that this client application is written in a different language or is created with an entirely different set of tools.

  1. Click File > New > Project.
  2. Expand EGL and click EGL Project.
  3. Click Next.
  4. Name the new EGL project EGLClient.
  5. Click Web Project.
  6. Click Next.
  7. Make sure that Create a new build descriptor is selected. You do not need to change the advanced settings unless you use WAS and have previously changed the settings to disable adding the project to an EAR.
  8. You may see a window asking if you want to switch to the J2EE perspective. If you see this window, click No.

Create the client web page

To use the service, you will create a web page in the client to retrieve input, pass that input to the service, and display the output from the service. You will start by creating a JSF Handler, a type of EGL logic part that controls a web page, and then EGL will create a web page to go along with this JSF Handler.
  1. In the Project Explorer view, click the EGLClient project to select it.
  2. Click File > New > Other.
  3. Expand EGL and click JSF Handler.
  4. Click Next.
  5. In the New EGL JSF Handler window, make sure that the Source folder field is set to the project's EGLSource folder:
    EGLClient\EGLSource
  6. In the Package field, type this name:
    jsfhandlers
  7. In the EGL source file name field, type this name:
    ClientPage
    The window looks like this:
    The New EGL JSF Handler window
  8. Click Finish. The new JSF Handler opens in the editor.

    Don't save the file until these instructions tell you to do so. When you save a JSF Handler, EGL checks to see if the web page referred to in the view property exists or not. If not, EGL creates the file and adds fields automatically based on the variables in the JSF Handler and the DisplayUse properties of those variables. If you save the file before you've added all the variables, the new web page will not include all of the variables. If this happens, you can delete the JSP file (not the JSF Handler file) and generate the JSF Handler again to get a new web page.

  9. Remove the sample code from the new JSF Handler so that the following is all that is left:
    package jsfhandlers;
    
    handler ClientPage type JSFHandler
       {view = "jspLocation/jspName.jsp"}
       
    end
  10. Set the value of the view property to ClientPage.jsp, as in this example:
    {view = "ClientPage.jsp"}
  11. Within the JSF Handler, create the following variables:
    name string {DisplayUse = input};
    city string {DisplayUse = input};
    output string {DisplayUse = output};
  12. Below the variables, add this function:
    function getHello()
    
    end
    You will add code to this function later. The JSF Handler looks like this:
    The code in the JSF Handler
  13. Save the file. When you save the file, EGL creates a web page from the file automatically. This file is named with the value of the view property, ClientPage.jsp, and the file is placed in the WebContent folder of your project.
    If you did not get a JSP file, EGL is not configured to generate JSF Handler parts automatically. Generate the JSF Handler manually by right-clicking it either in the Project Explorer view or in the EGL editor and then clicking Generate. Then, follow these additional steps to set up automatic generation of JSF Handlers:
    1. Click Window > Preferences.
    2. In the Preferences window, click EGL and ensure that EGL support with JSF and EGL support with JSF Component Interfaces are selected.
    3. Expand EGL and click Generation.
    4. On the Generation page, select the Java check box.
    5. Click OK.

    Now JSF Handlers will generate automatically when you save them.

  14. Open the ClientPage.jsp file in the editor. This page has fields on it based on the variables you created in the JSF Handler. These fields are pre-bound to the variables. This way, when the values of these fields change on the page, the variables will change to match. Similarly, when the values of the variables in the JSF Handler change, the values of the fields on the page will change to match.

    This page also has several error message fields. This does not mean that your page has errors; these fields will show errors on the page if there are any when you run it.

  15. Locate the Page Data view. If you cannot find this view, click Window > Show View > Page Data. This view shows the data available to your page, including the variables you created in the JSF Handler. It also shows functions in the JSF Handler.
  16. In the Page Data view, expand JSF Handler > Actions and find the getHello() function.
  17. Drag the getHello() function from the Page Data view directly onto the bottom of the page. A button bound to the function appears on the page. When the user presses the button on the page at run time, the function in the JSF Handler will run.
  18. Save the page.
The page looks like this:
Appearance of the client web page

You now have a web page ready to use the web service. In the next lesson you will set up the project to act as a client for the service through this web page.

< Previous | Next >

Feedback