Using a Web Service in ADF

An Oracle JDeveloper How To Document
Written by Susan Duncan
March , 2004

Contents

Prerequisites
Create the Data Control Layer
Use Web Service Data Control in a Struts Page Flow
Use Web Service Data Control in a JSP
Pass Parameter to Web Service Data Control
Troubleshooting
Conclusion and where to get more information

Introduction

This How to describes the steps to use a web service in the Application Development Framework (ADF). The example uses two web services methods: one returns a JavaBean and the other takes a parameter that is passed from a previous page.

Prerequisites

  1. Download and store example application
  2. Open the ADF_WS_HowTo application in JDeveloper
  3. In the model project, select the PersonWS and run it in the embedded OC4J

Create the Data Control Layer

The data control layer exposes the web service to clients. The ADF framework creates the data bindings for you, so the only thing you need to do in this step is to create the data control.

  1. Use the context menu of the PersonWS web service node to Create Data Control



  2. Note that the following files are generated and appear in the Navigator
    PPersonWS.java is the DataControl that exposes the methods and accessors in the web service.
    PPersonWSBeanInfo.java is the bean info class, which hides the system methods appearing in the Data Control Palette.
    PPersonWS.xml contains the metadata for the DataControl methods and accessors
    Person.xml contains the metadata for the Person JavaBean used by the DataControl
  3. If not already open, open the Data Control Palette (View menu)
    Note that the new data control PPersonWSDataControl is available in the palette

Use Web Service Data Control in a Struts Page Flow

  1. Use the context menu of the ViewController project node to Open Struts Page Flow Diagram
  2. Drag a DataPage from the Struts Page Flow Component Palette onto the diagram
  3. Name the DataPage /listing
  4. In the Data Control Palette select the giveMeSomePeople operation
  5. Note that the Drag and Drop As list shows Method



  6. Drag and drop giveMeSomePeople onto /listing in the Page Flow Diagrammer.
  7. In the Structure panel examine the ActionMapping that has been created for /listing



  8. Add a second Data Page to the diagram named /greeting
  9. Drag and drop echoName as a Method onto /greeting to create the ActionMapping

Use Web Service Data Control in a JSP

Create listing.jsp

  1. Double-click /listing in the diagram and create listing.jsp
  2. In the Data Control Palette select the return of the giveMeSomePeople operation



  3. Drag and Drop it as a Read-Only Table onto listing.jsp
  4. Select and delete the ${Row.currencyString} element from the first column of the iteration. Note that you can use the Structure Pane to ensure you select the correct element


  5. Select the return of giveMeSomePeople in the Data Control Palette
  6. Drag and Drop it as a Select Row Link into the now empty column



  7. In the Structure Pane, use the Edit Tag context menu of the Select element to open the Edit Link dialog



  8. Change the text to Greet
  9. Change the default Struts action to greeting.do



  10. In listing.jsp change to the Source view. Find the link code

    <tr>
    <td>
    <a href="greeting.do?rowKeyStr=<c:out value='${Row.rowKeyStr}' />">Greet</a>
    </td>
    <td>
    <c:out value="${Row['id']}"/>&nbsp;
    </td>
    <td>
    <c:out value="${Row['name']}"/>&nbsp;
    </td>
    </tr>

  11. Change the parameter name rowKeyStr to pName

    <a href="greeting.do?pName=<c:out value='${Row.rowKeyStr}' />">Greet</a>
  12. Replace '${Row.rowKeyStr}' with the expression language for the name field "${Row['name']}"

    <a href="greeting.do?pName=<c:out value="${Row['name']}" />">Greet</a>
  13. Return to the stuts-config page flow diagram
  14. Use the context menu of /listing to Refresh Diagram from Page. The link from /listing to /greeting is displayed
  15. Save All
  16. Run /listing
    The embedded server is started, the web service is running and the giveMeSomePeople method is called
  17. Check that the list of people is displayed in the browser and that the parameter pName is included in the URL to greeting.do. The jsp is not displayed as you have not yet created it.

Create greeting.jsp

  1. Double-click /greeting in the diagram and create greeting.jsp
  2. (Optional) add some text and a CSS to the jsp
  3. In the Data Control Palette select the return of the echoName(String) operation


Pass Parameter to Web Service Data Control

  1. Return to the page flow diagram and select /greeting
  2. In the structure pane expand the /greeting Action Mappings
  3. Select numParams and note that one parameter is expected
  4. Select paramNames[0]
  5. In the Property Inspector change the value to ${param.pName}



  6. Save All
  7. Run /listing from the diagram

Click the Greet link and check the correct name has been passed as a parameter to /greeting and displayed correctly

Troubleshooting

Problem Possible Solution
listing.jsp does not return the rows the web service is not running
greeting.jsp does not show the name you have not correctly passd the parameter to greeting.do. See Pass Parameter

Conclusion and where to get more information

This How To shows how easy it is you use a web service in ADF. ADF hides the complexity and underlying implementation from the developer and a web service can be used like any other component (Java class, EJB etc.) that is exposed as a Data Control.

Further Information
OTN Web Services Technology Centre

 

false ,,,,,,,,,,,,,,,