Contents
Overview
* Use Data control for external ws
Environment
* JDeveloper 11.1.1.6.0
Steps
* Create a new application and project
* Create Java classes
* Create an EJB ws
* Create a WS data control
* Create a JSF page
* Add data control to the page
* Set the labels
Create a New Application and Project
* Create a new JDev application named WSDataControlApp
– Application package prefix: oracle
– Application template: Java EE Web Application
* Accept all defaults for the ViewController project:
* Rename the Model project to EJBModel
* WSDataControlApp:
Create Java Classes
* Select EJBModel project.
* Create a new Java class named BatchOrder with package name oracle.model.freight
– Add two properties and generate getter/setter methods:
package oracle.model.freight; public class BatchOrder { private Long batchId; private Long orderedQuantity; public void setBatchId(Long batchId) { this.batchId = batchId; } public Long getBatchId() { return batchId; } public void setOrderedQuantity(Long orderedQuantity) { this.orderedQuantity = orderedQuantity; } public Long getOrderedQuantity() { return orderedQuantity; } }
* Create another Java Enumeration class named FreightDestination
package oracle.model.freight; public enum FreightDestination { LOCAL(1.0), REGIONAL(2.0), NATIONAL(3.0), INTERNATIONAL(4.0); Double factor; private FreightDestination(Double factor) { this.factor = factor; } public Double factor() { return this.factor; } }
* Create another Java Enumeration class named CustomerCode
package oracle.model.freight; public enum CustomerCode { PLATINUM(20D), GOLD(10D), SILVER(5D), BRONZE(2D), OTHER(0D); Double factor; private CustomerCode(Double factor) { this.factor = factor; } public Double factor() { return this.factor; } public Double calculateDiscount(Double originalPrice) { return (originalPrice * factor) / 100; } }
Create an EJB Web Service
* Select EJBModel project.
* Start Create Session Bean wizard by selecting File > New > Business Tier > EJB > Session Bean
– EJB Name: CalculateFreight
– Session Type: Stateless
– Transaction Type: Container
* Use package name oracle.model.freightejb (note freightejb not freight):
* De-Select both Implement a Remote Interface and Implement a Local Interface because we’re exposing the service as a web service:
* Add a business method named calculateFreightCost to the newly crated session bean:
package oracle.model.freight; import javax.ejb.Stateless; import oracle.model.freight.BatchOrder; import oracle.model.freight.CustomerCode; import oracle.model.freight.FreightDestination; @Stateless(name = "CalculateFreight", mappedName = "WSDataControlApp-EJBModel-CalculateFreight") public class CalculateFreightBean { public CalculateFreightBean() { } private static final Double BASE_COST = 10D; public Double calculateFreightCost(BatchOrder order, FreightDestination destination, CustomerCode customer) { Double totalCost = BASE_COST + order.getOrderedQuantity() * destination.factor(); Double discount = customer.calculateDiscount(totalCost); return totalCost - discount; } }
Create a Web Service
* Right click CalculateFreightBean and select Create Web Service… to start Create Java Web Service wizard:
* Select SOAP 1.2 Binding and Document/Wrapped
* Accept defaults for the rest of screens:
Test Web Service
* Right click CalculateFreightBean.java and select Test Web Service
* Test domain will be crated if not already created before:
* HTTP Analizer:
* Do not close HTTP Analyzer as it’s needed for Web Service Data Control WSDL retrieval below.
Create a Web Service Data Control
* Select File > New > General > Projects > Generic Project to create a new project named DataControl
* Select DataControl project
* Start the Create Web Service Data Control wizard by selecting File > New > Business Tier > Data Controls > Web Service Data Control
* Name the data control FreightCost and WSDL URL is
http://localhost:7101/WSDataControlApp-EJBModel-webapp/CalculateFreightBeanService?WSDL
* Shuffle the only available service to the right panel:
* Stop HTTP Analyzer and Integrated WLS
* Save all.
Create a JSF Page
* Select ViewController project.
* Add ADF Faces Components 11 to project tag libraries
* Add a new JSF page named CalculateFreightCost.jspx by selecting File > New > Web Tier > JSF > JSF Page.
Add WS Data Control to the Page
* Select the newly created JSF page.
* Drag and drop Panel Group Layout to the blank page.
* Expand Data Controls > FreightCost > calculateFreightCost_parameters
* Drag arg0 into the panel group layout component. Select ADF Form and accept all defaults.
* Drag Data Controls > calculateFreightCost to Structure > … > footer.
– Select ADF Button and accept all defaults
* Drag Data Controls > arg1 and drop it into Structure > … > af:panelFormLayout.
– Select Text > ADF Input Text w/ Label
* Drag Data Controls > arg2 and drop it into Structure > … > af:panelFormLayout.
– Select Text > ADF Input Text w/ Label
* Drag Data Controls > Double and drop it into Structure > … > af:panelGroupLayout (note not panelFormLayout).
– Select Text > ADF Output Text w/ Label
* Drag and drop a Separator component into separator facet:
* Save all.
* Right click CalculateFreightCost.jspx and select Run
Set the Labels
* Set batchId label to Order Number
* Set orderQuantity label to Quantity
* Set calculateFreightCost button label to Calculate Cost
* Run jsf page: