Lesson 2: Create and test a Web page that uses the bean

Next, create a Web page, bind it to the business logic in the service managed bean you just created, generate the Web page layout, and then test the Web page by running it on a server.

StepsCreating the Web page

  1. Select File|New|Web Page from the main menu.

    The New Web Page File wizard opens.

  2. In the Create a New Web Page File page, make sure the parent folder is Tutorial\webroot.

  3. In the File name field, enter getTimeService.

  4. Click Finish to create the getTimeService.jsp page.

    Sybase WorkSpace creates a getTimeService.jsp file with default JSF contents and opens it in the Web Page editor.

StepsMapping the JSF components to the beans attributes

Map the appropriate JSF components to the service managed bean attributes and then generate the layout of the getTimeService.jsp page using the service managed bean that you just created..

  1. In the Data Bindings view, drag and drop the LocalTimeSoap bean onto the design pane of the getTimeService.jsp page to open the Create JSF Components wizard to create JSF components that map to the managed bean’s attributes.

    As required, expand the wizard and the columns to see the entire attribute name and/or label.

  2. Move the Fault class member to the bottom of the list.

    Select the row and click Move Down multiple times until the Fault class member is at the bottom of the list.

  3. Accept the default values in the Label field and click Next.

  4. Make sure that JSF panelGrid is selected as the generated container, accept the remaining default values, and click Finish.

    The Create JSF Components wizard generates a Web page grid with ZipCode as the input value and Local Time as the output value.

  5. Select File|Save from the main menu bar to save the getTimeService.jsp page.

  6. Select the Preview tab at the bottom of the editor to preview the Web page in the Web Browser view.

StepsTesting the getTimeService.jsp Web page

  1. In the WorkSpace Navigator, expand the webroot folder, right-click the getTimeService.jsp, and select Run from the context menu.

  2. In the Run On Server wizard, select Choose an existing server, and select Tomcat v.5.0 Server @ localhost from the list.

    NoteIf you completed all previous tutorials in this guide, you already defined the Tomcat server. However, if it does not appear on the list, see “Starting the Tomcat 5.0 server” for step-by-step instructions.

  3. Click Finish.

    The Apache Tomcat server starts, and the JSF Page Template view displays your Web page.

  4. To test the Web page, enter a zip code in the Zip Code field, and click Submit.

  5. View the results in the Local Time By Zip Code Result field.

  6. Click the Stop the server icon in the Servers view to stop the server before continuing.

    You are now ready to link the two Web pages you previously created, login.jsp and getTimeService.jsp. Continue to Chapter 5, “Linking Web Pages.”