 | Create a Web Page Using the Service
Let’s now create a Web page that utilizes this external service. From the LAB7_Web_Service project,
-
Right click WebContent, and select New > Web Page, as shown in Figure 42.
Figure 42. Create a new Web page
-
In the New Web Page dialog that displays (Figure 43):
-
Specify the file name as moviePage.jsp.
-
Pick any template under Sample Templates > Family A (no navigation) > A_green.htpl
-
Clear the Link page to template option.
-
Click the Finish button.
Figure 43. Select name, location, and
template for a new Web page
The page will now be created and open in the content view.
-
Add Let’s Go To The Movies as header text after the heading.
-
Press the Enter key twice, to add some blank lines on the page, as shown in Figure 44.
Figure 44. Content view
-
Right-click anywhere on the page and select Edit Page Code, as shown in Figure 45.
Figure 45. Edit the code
-
The JSF Page Handler for moviePage.jsp opens in the content area (Figure 46).
-
Add 3 variables
-
zipCode string;
-
radius int;
-
theaters Theater?[0];
-
Use content assist (Ctrl + spacebar) when specifying the data type for the variable
theaters. This will add the import statement automatically to this EGL page handler file.
-
Also, specify that
theaters is a dynamic array by specifying the square brackets [0]. The zero indicates that the array initially has zero elements.
-
Add a function with the name
findmovies().
Figure 46. Modify the code
In this function, you will invoke the GetTheatersAndMovies Web service, which is defined in the moviefunctions.egl source that got created for you.
First, you have to declare a variable that points to the interface description MovieInformationSoap for this Web service, which is contained in moviefunctions.egl.
-
Inside the findMovies function:
-
Add the
movieInformationSoap variable (use content assist for the type and the attribute).
-
Add the one
assignment statement (use content assist to create the statement).
-
Save the moviePage.egl Page Handler file.
-
Fix any problems that display.
-
Then after the page handler source is error free:
-
Click the moviePage.jsp tab at the top of the content area to return to the page designer view.
-
Save the file to refresh and synchronize the tools.
Add controls to the Web page
You now need to fill the Web page with controls.
You need two input fields for specifying which ZIP code area the theaters should be selected from, and what the radius should be that you are interested in. You also need a button on the page to invoke the search for movie theaters (your findMovies function).
From the Page Data view at the left bottom side of the workbench,
-
Press the control button and select:
-
the
radius variable
-
the
zipCode variable,
-
the
findMovies function.
-
With all three items selected, drag them onto the page, as shown in Figure 47.
Figure 47. Drop to insert new controls
-
In the Configure Data Controls dialog that displays (Figure 48):
-
Select Updating an existing record, which will cause an input field to be created.
-
Click Options.
-
Because you have your own button to add, you don’t need the default buttons, so clear the boxes next to Submit Button and Delete Button.
-
Click the OK button, then the Finish button.
Figure 48. Specify columns to display and how to display them
-
Specify the same exact things when the next window displays. The page should now look like that shown in Figure 49.
Figure 49. Updated content view
-
To add the output fields that are returned from the service, drag theaters onto the page underneath the findMovies button, as shown in Figure 50.
Figure 50. Add output fields
-
In the window that displays, select Displaying an existing record (read-only).
Configure the array
Because the theaters record contains the Movies variable (which is an array), you need to specify how this array should look like on the page.
-
To do this, click the ellipsis next to Multi-Column Data in the Movies (Movie[]) row, as shown in Figure 51.
Figure 51. Configure Data Controls
-
The same window displays, but with different Columns to display.
-
Select Displaying an existing record (read-only)
-
Click the Finish.
-
You will now be focused on the previous window where you clicked the ellipsis, Click the Finish button there as well.
-
Your page should now look like that shown in Figure 52.
Figure 52. Updated page
Add the application to the server
-
At the bottom of the workbench in the server view:
-
Right click the server
-
Select Add and Remove Programs, as shown in Figure 53.
Figure 53. Add a project to the server
-
Select Lab7WebServiceEAR from Available projects.
-
Press the Add button to add it to Configured projects, as shown in Figure 54.
-
Click Finish.
Figure 54. Add and Remove Projects dialog
-
Back in page designer, right-click anywhere on the moviePagepage,jsp and select Run on Server, as shown in Figure 55.
Figure 55. Run on server
The Web page appears in the build in the workbench browser.
-
Enter a ZIP code (27518 is Raleigh, NC if you don’t know a valid ZIP code).
-
Enter a distance in miles for the radius to be used (for example 10).
-
You should see a couple of movie theaters in the region of your ZIP code and the movies they are playing today, as shown in Figure 56.
Figure 56. Query results
Most likely, you’ll be interested in something other than the movies playing today in your business application, but this could be any Web service. You now know how to access Web services from EGL, and can use this in your own business applications in Rational Business Developer.
 |
What you have done so far
You have now generated code from a third party WSDL and created a Web page to test it, using Rational Business Developer. You also coded EGL business logic to run your page.
Going forward, you can use the skills you learned in this tutorial, and you can start implementing SOA-based applications written in EGL.
|
|
|  |