Consume a Web Service from a Web Page

The most common way of using web services in an ADF JSF application is to create a data control for an external web service. A typical reason for doing this is to add functionality that is readily available as a web service, but which would be time consuming to develop with the application, or to access an application that runs on a different architecture. You can work in JDeveloper's IDE to quickly create a data control from a web service. You can also test the web service by running it on JDeveloper's integrated server, and running a page that consumes the data control.

Create a New Application and Project: Use the Create Application wizard to create a Java EE web application.

Create Java Classes: Create three Java classes containing bean attributes, constants, and a method.

Create an EJB Web Service: Create a session bean and a business method, then use the Create Java Web Service wizard to publish the bean and expose the method as a web service operation.

Create a Web Service Data Control: Use the Create Web Service Data Control wizard to generate the data control.

Create a JSF Page: Use the Create JSF Page dialog to create a starter page for adding UI components.

Add the Data Control to the Page: Use a series of drag-and-drop steps from the Data Controls panel in the Application Navigator to create databound UI components on your JSF page.

Set the Labels: Use the Property Inspector to set labels for some components.

 

Create a New Application and Project

tell me more icon Creating a New Application and Project

The JDeveloper application is the highest level in the organizational structure. It stores information about the objects you are working with, while you are creating your application. It keeps track of your projects and the environment settings while you are developing.   [ tell me more...]





  1. Open the Create Application wizard [ File > New > General > Applications] .
  2. To follow along with the example, enter the application name WSDataControlApp.
  3. In the A pplication Package Prefix field, enter oracle.
  4. Select Java EE Web Application in the Applica tion Template list, and click Next three times.

    tell me more icon Application Templates

    Application templates provide you with a quick way to create the project structure for standard applications with the appropriate combination of technologies already specified. The new application created from the template appears in the Application Navigator already partitioned into tiered projects, with the associated technology scopes set in each project.   [ tell me more...]



  5. On step 4, enter EJBModel as the name for the model project, and click Finish .

    tell me more icon In the IDE

    When you complete the steps for creating a new application and project, the Projects panel in the Application Navigator should look like this:  [ tell me more...]



 

Create Java Classes

tell me more icon Creating a Java Class

To follow along with the example, in this step and throughout the cards, enter values as shown in the instructions. Then you will be able to follow the steps in the cue cards exactly as written.   [ tell me more...]





  1. To be able to follow the steps in the cue cards exactly as written, enter values as shown in the instructions in this step and throughout the cards. Before creating a web service data control, you have to create Java classes from which a session bean will be generated. Later a web service will be generated for the session bean.
  2. In the Application Navigator, select the EJBModel project and open the Create Java Class dialog [ File > New > General > Simple Files > Java Class] .
  3. Enter BatchOrder as the class name, and oracle.model.freight as the package name. Accept the remaining defaults and click OK.

    tell me more icon Java Class Name and Package

    In the Create Java Class dialog, the name you specify in the Name field will become the file name for the class. The package name you enter in the Package field (or select from the Package Browser) will become the default package for subsequent Java classes that you create in the project.   [ tell me more...]



  4. In the source editor, add two properties and their getter and setter methods.
    code sample icon Use sample code

    tell me more icon Editing a Java Class

    The new Java class opens in the source editor. The generated code includes only the class and package that you specified:  [ tell me more...]



  5. Repeat steps 2 and 3 to create two more Java classes in the same package, using the following class names: FreightDestination and CustomerCode.
  6. In the editor window, click the FreightDestination.java tab to bring the file forward. In the source editor, add code to represent a fixed set of destination constants.
    code sample icon Use sample code
  7. In the editor window, click the CustomerCode.java tab to bring the file forward. In the source editor, add code to represent a fixed set of customer code constants, and a method to calculate a customer discount.
    code sample icon Use sample code
  8. Click the save all icon Save All to save your work.

    tell me more icon In the IDE

    When you complete the steps for creating three Java classes, the Application Navigator should look like this:  [ tell me more...]



 

Create an EJB Web Service

tell me more icon Creating an EJB Web Service

In JDeveloper's IDE, you can quickly create a session bean and create business methods declaratively. To begin creating a session bean, you will open the Create Session Bean wizard. To open the wizard, in the Application Navigator, right click a project and choose New . In the New Gallery, expand Business Tier and select EJB in the Categories tree and select Session Bean from the Items list, and click OK.   [ tell me more...]





  1. Before creating a web service data control, you have to create a session bean and a business method, using the Java classes you created previously. Then you can create a web service to expose the business method as an operation in the service.
  2. In the Application Navigator, select the EJBModel project and launch the Create Session Bean wizard [ File > New > Business Tier > EJB > Session Bean] .
  3. On step 2 of the wizard, EJB Name and Options, enter CalculateFreight as the EJB name. Make sure State less and Container are selected. Confirm that Generate Session Facade Methods is not selected. Click Next .

    tell me more icon Session Beans

    A session bean is a short-lived object containing business methods that can be executed by a client. In the example you are creating a stateless session bean that implements a CalculateFreightCost business method, hosted in an EJB container.   [ tell me more...]



  4. On step 3, Class Definitions, enter oracle.model.freightejb.CalculateFreightBean as the bean class name, and click Next .
  5. On step 4, EJB Home and Component Interfaces, deselect both Implement a Remote Interface and Imp lement a Local Interface . Click Finish .
  6. In the source editor of CalculateFreightBean.java, add code to create a business method for calculating freight cost. (If not already open, double-click CalculateFreightBean.java in the Application Navigator to open the file in the editor.)
    code sample icon Use sample code
  7. In the Application Navigator, right-click CalculateFreightBean.java and choose Cr eate Web Service to launch the Create Java Web Service wizard.

    tell me more icon EJB Web Services

    You can also launch the Create Java Web Service wizard from the New Gallery. In the Application Navigator, right-click the project and choose New . In the New Gallery, All Technologies page, select Web Services under Business Tier in the Categories tree and Java Web Service in the Items list, then click OK.   [ tell me more...]



  8. On step 2 of the wizard, Generation Options, make sure CalculateFreight is shown in the Componen t to Publish box. Accept the default web service and port name, and click Next .
  9. On step 3, Message Format, select SOAP 1. 2 Binding , then confirm that Document/Wrapped is selected as the SOAP Message Fo rmat . Click Next .
  10. On step 4, Methods, make sure the calculateFreightCost() method is selected. Click Finish . You should see the message Generation complete in the Web Services Log window.
  11. In the Application Navigator, right-click CalculateFreightBean.java node and choose Test Web Service .

    tell me more icon Testing the Web Service Using the HTTP Analyzer

    After you create a web service, you will usually test it to ensure that you get the results you expect. JDeveloper's IDE allows you to deploy the web service to an integrated server for testing.   [ tell me more...]



  12. In the Request pane of the HTTP Analyzer test window, parameters section, select Include next to arg0. Enter 1 and 10 in the batchId and orderedQuantity fields, respectively. Then enter LOCAL and GOLD in the arg1 and arg2 fields, respectively. Click the send request icon Send Request. You should see 18.0 in the Response pane.
  13. Do not stop the application, Integrated WebLogic Server or close the main HTTP Analyzer window. You will need the web service to be running when you create a web service data control. Take note of the WSDL URL in the analyzer window.

    tell me more icon In the IDE

    When you complete the steps for creating the web service using the wizard, the Application Navigator should look similar to this:  [ tell me more...]



 

Create a Web Service Data Control

tell me more icon Creating a Web Service Data Control

The most common way of using web services in an application is to create a data control for an external web service. A typical reason for doing this is to add functionality that is readily available as a web service, but which would be time consuming to develop with the application, or to access an application that runs on a different architecture.   [ tell me more...]





  1. Launch the Create Generic Project wizard [ File > New > General > Projects > Generic Project]  to create a new generic project. Enter DataControl as the project name and click Finish .
  2. In the Application Navigator, select the project you just created and launch the Create Web Service Data Control wizard [ File > New > Business Tier > Data Controls > Web Service Data Control] .
  3. On step 1 of the wizard, Data Source, enter FreightCost as the data control name.

    tell me more icon WSDL URL

    WSDL or web service description language, is a description language that defines how to communicate with a web service. When you use the Create Web Service Data Control wizard to generate a data control, you will need to reference the WSDL URL that JDeveloper automatically generated when you tested the web service in the integrated server.   [ tell me more...]



  4. In the URL field, enter the WSDL URL you noted from the analyzer test window in the previous cue card. Then press Tab. You should see {http://freightejb.model.oracle/}CalculateFeightBeanService populated in the Service dropdown list.
  5. Click Next .
  6. On step 2, Data Control Operations, shuttle icon shuttle the selected operation from the A vailable pane to the Selected pane. Click Finish .
  7. Click Terminate red icon Terminate on the main toolbar and choose IntegratedWebLogicServer from the dropdown menu. Below the editor window, click the HTTP Analyzer log window tab, then click terminate icon Terminate on the HTTP Analyzer toolbar.
  8. In the Application Navigator, expand the Data Controls panel. Click the save all icon Save All to save your work.

    tell me more icon In the IDE

    When you complete the steps for creating the web service data control, the Application Navigator should look similar to this:  [ tell me more...]



 

Create a JSF Page

tell me more icon Creating a JSF Page

The JSF pages you create for your application can be JSP pages (which uses the file extension .jsp) or JSP documents written in XML syntax (which uses the file extension .jspx). Oracle recommends that when creating pages with ADF Faces components, you use XML-based JSP documents that use .jspx rather than .jsp files.   [ tell me more...]





  1. In the Application Navigator, select the ViewController project and open the Project Properties dialog, JSP Tag Libraries page. [ Tools > Project Properties > JSP Tag Libraries
  2. Select the Distributed Libraries folder, then click Add .
  3. In the Choose Tag Libraries dialog, select ADF Faces Components 11 and click OK.

    tell me more icon JSP Tag Libraries

    Libraries are provided for the various APIs and technologies installed with JDeveloper. These libraries are categorized as extension libraries, which are shared by all users of an install.   [ tell me more...]



  4. Click OK to close the Project Properties dialog.
  5. In the Application Navigator, select the ViewController project and open the Create JSF Page dialog [ File > New > Web Tier > JSF > JSF Page] .
  6. Enter CalculateFreightCost.jspx as the file name.
  7. Confirm that Create as XML Document (*.jspx) is selected. Under Initial Page Layout and Content, make sure Blan k Page is selected.
  8. Make sure Page Implementation shows UI Components are not exposed in managed bean. Click OK.
  9. Click save all Save All to save your work.

    tell me more icon In the IDE

    When you complete the steps for creating a JSF page, the visual editor should look similar to this:  [ tell me more...]



 

Add the Web Service Data Control to the Page

tell me more icon Adding the Web Service Data Control to the Page

A data control is a representation of a business service, and comprises a hierarchical display of available business objects, including collections, attributes, and methods.   [ tell me more...]





  1. In the Component Palette, ADF Faces page, Layout panel, drag panelgrouplayout icon Panel Group Layout and drop it on the blank page in the visual editor.
  2. In the Data Controls panel, expand FreightCost | calculateFreightCost_parameters.

    tell me more icon Data Controls Panel and UI Controls

    The Data Controls panel comprises a hierarchical display of available business objects, including collections, attributes, and methods.   [ tell me more...]



  3. Drag the argo0 node and drop into the panel group layout component on the page in the visual editor. From the Create context menu, choose Form then choose ADF F orm . In the Edit Form Fields dialog, accept all the default values and click OK.
  4. In the Structure window, right-click af:panelFormLayout and choose Facets - Panel Form Layout then choose Footer from the context menu.
  5. In the Data Controls panel, drag calculateFreightCost() and drop it into footer in the Structure window. From the Create context menu, choose Method then choose ADF Button . In the Edit Action Binding dialog, accept all the default values and click OK.
  6. In the Data Controls panel, expand the calculateFreightCost() method node, then expand Parameters.
  7. Drag arg1 and drop it into af:panelFormLayout in the Structure window. Choose Text then choose ADF Input Text w/ Label from the Create menu.
  8. Drag arg2 and drop it into af:panelFormLayout in the Structure window. Choose Text then choose ADF Input Text w/ Label from the Create menu.
  9. Drag Double and drop it into af:panelGroupLayout in the Structure window. Choose Text then choose ADF O utput Text w/ Label from the Create menu.
  10. In the Structure window, expand Panel Group Layout facets to reveal the separator facet.
  11. In the Component Palette, Layout panel, drag separator icon Separator and drop it into the separator facet.
  12. In the Application Navigator, ViewController project, right-click CalculateFreightCost.jspx and choose R un .

    tell me more icon In the IDE

    When you complete the steps for adding the data control to the page, the visual editor should look similar to this:  [ tell me more...]



 

Set the Labels

tell me more icon Setting the Labels

Oracle ADF control hints provides a centralized mechanism for any JavaBeans-based business service data item to be rendered in a consistent manner across all client types. This mechanism, known as control hints, permits application developers to centralize certain UI settings across clients and thereby control many aspects of the way the UI interacts with the data item. Because the control hints are set at the level of the business service, it can also reduce the amount of UI coding.   [ tell me more...]





  1. In the Application Navigator, DataControl project, select arg0.xml.
  2. In the Structure window, select batchId.
  3. In the Property Inspector, UI Hints section, enter Order Number in the Label field and press Enter.

    tell me more icon Generated Resource Bundles

    The file that defines the value for the control hints you set depends on the specific business service used for the project. In the case of beans-based business services, (including JavaBeans, Enterprise JavaBeans, and Oracle TopLink), by default JDeveloper generates a standard .properties file for the project and saves the control hint definitions as translatable strings.   [ tell me more...]



  4. Repeat the procedure to add a label for the attribute orderedQuantity, using the label text Quantity.

    tell me more icon Control Hints

    You can also use the Edit Attribute dialog to add ADF control hints. To open the Edit Attribute dialog, first you double-click the .xml definition file (for example, arg0.xml) in the Application Navigator to open the file in the default overview editor.  [ tell me more...]



  5. In the visual editor of CalculateFreightCost.jspx, select the button on the page. In the Property Inspector, change the Text value to Calculate Cost.
  6. In the Application Navigator, right-click CalculateFreightCost.jspx and choose R un .

    tell me more icon In the IDE

    When you run the JSF page again, the page in the browser should look similar to this, with the new labels you added:   [ tell me more...]



 















Copyright © 1997, 2009, Oracle. All rights reserved.

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