-
Open EmpsTaskFlow.xml in the editor.
-
Add a View Activity from the Component Palette to the task flow and name it SalaryUpgrade.
-
Drag another View Activity to the task flow and name it TakePicture.
-
Draw a Control Flow Case between empList and TakePicture. Name the flow takePicture.
-
Draw a Control Flow Case between EmpList and SalaryUpgrade. Name the flow goWS.
In this part of the tutorial, you add view components and navigation rules to the existing application. You will create the pages for these components in the next section.
You now have the components on which you will base the remainder of the application.
In this section, you open and run a web service that you will use in your application. You then create a data control based on the web service and consume the data control from your application.
-
In the Preparation step of this tutorial, you downloaded SampleWS.zip and extracted it into a myWork directory of your choice. If you did not do that, go to the beginning of this tutorial and download and extract that file now.
-
In JDeveloper click File > Open and navigate to the directory you used when you unzipped SampleWS.jws. Select SampleWS.jws and click Open.
-
In the Application Navigator, expand Project 1 > Application Sources > a to show Service.java. Right-click Service.java and select Run.
-
If this is the first time you have invoked the WebLogic Server (WLS), it will prompt you for a password. Enter a password, confirm the password, and click OK. If you are running WLS for the first time, it builds a default domain and might take a few minutes to start.
-
When the web service is deployed and running, you see a completion message in the Running messages tab. pane when the web service is deployed and is running. IMPORTANT NOTE: If the web service stops for any reason, you must restart the web service or your deployed mobile application will not function correctly. Specifically, you will see a failure when you try to update an employee's salary.
-
Click the link for the Target URL to open the HTTP Analyzer. You can use the HTTP Analyzer to test the web service. If you were to enter values in each of the parameters and click Send Request. The web service will process the request and return the results all from within the HTTP Analyzer.
-
Right-click the WSDL URL near the top of the Analyzer pane and select Copy. You will use this WSDL address when you create the Data Control.
-
Use the drop down list in the Application Navigator to navigate back to the Employees workspace.
-
Right-click the ViewController project and select New.
-
In the New Gallery, select Business Tier > Data Controls > Web Service Data Control and click OK.
-
If you deploying to a device or an emulator, you need to specify the IP address of the machine on which the web service is running.
-
To find the IP address on a Windows machine, start a command window (select Start > Run, enter CMD, and then click OK.)
-
In the command window, type ipconfig and press enter.
-
Copy the IP address of the machine. Use that IP Address in the URL of the web service data control. THe image below has the I.P. address blacked out for security purposes.
-
-
In the Create Web Service Data Control wizard, name the web service data control SalaryService, and paste the URL of the WSDL into the URL field. Click Next.
Again, for security purposes, the I.P. address is not visable in the image below. -
Select the SalaryUpgrade method, shuttle it to the Selected list, and click Finish.
-
Save your work.
-
Open the Data Controls palette and click Refresh to see the new web service data control, SalaryService.
Now that the web service is running, you switch back to the Employees workspace to use the web service.
You now have a Data Control that is based on the SalaryService web service. In the next few steps, you create the SalaryUpgrade page for the view activity you added earlier. You also add navigation to the EmpsList page.
In ADF, the steps for consuming all data controls are the same. It doesn't matter if the data control is based on a Java class, an ADF Business Component, or a web service. In this section, you add elements to your application that consume the Salary Service data control.
-
Open EmpsList.amx in the editor.
-
As you did earlier, use the splitter in the editor to view both the code and the preview of the page.
-
Choose iPad as the device type so you can see more detail on the screen while you are working on the page.
-
In the source code editor, select the button with the Id cb2 (the right-most button on the page). I the Property Inspector, set the Text to Update and the Action to goWS.
-
Save your work.
-
Open EmpsTaskFlow.xml in the editor.
-
Double-click SalaryUpgrade to create the page. Click OK to accept the default values for the new page.
-
To show the employee data, drag the emps collection to the Panel Page and drop it as an ADF Mobile Form.
-
Remove all the attributes except for Name and Salary and click OK to add the form to the page.
-
Click the Bindings tab at the bottom of the editor to see that the bindings for Name and Salary are added to the page.
-
To ensure that you have the row you want, add an Action binding that will call the method. Click the Add icon (the green plus sign ) on the Bindings panel.
-
Select action as the binding type and click OK.
-
In the Create Action Binding editor, select the empsIterator and set the Operation to setCurrentRowWithKeyValue.
-
Set the Value property of the rowKey parameter to #{pageFlowScope.empId}. Remember that you created this variable to store the current rowKey from the previous page, empList.amx.
-
Click the Add icon (the green plus sign) on the Executables panel.
-
Select invokeAction as the type and click OK.
-
Set the id the setEmpId and Binds to setCurrentRowWithKeyValue. Click OK.
-
Notice that the invokeAction is the last executable in the list. This action sets the current row in the iterator, so it should be the first action to be executed.
-
Drag setEmpId to the top of the executables list.
-
Save your work.
-
Click the Source tab on the SalaryUpgrade.amx page.
-
From the SalaryService data control, drag the SalaryUpgrade method to the Panel Page and drop it as an ADF Mobile Button.
-
Click the down arrow next to the Value property of the name parameter and click Show EL Expression Builder.
-
Use the Expression Builder to select bindings.name.inputValue and click OK. (The expression gets the current value of the name field on the form.)
-
Repeat those steps for the sal field. (HINT: In the Expression Builder, select bindings.salary.inputValue and click OK.)
-
Using the same process as before, select the date parameter and set the Value to #{viewScope.start}
-
Using the same process as before, select the comm parameter and set the Value to #{viewScope.commission}.
-
Click OK to create the button.
-
Save your work.
-
Click the bindings tab to examine the bindings you just added.
-
Expand SalaryUpgrade in the Structure pane to see the parameters.
-
Click each of the parameters and notice in the Property Inspector that you can see the ND values for each of the parameters.
-
Click the Source tab on the SalaryUpgrade page and drag a Switch (boolean) component from the Component Palette to the Panel Form Layout component in the Structure window.(HINT: The Switch component is under Text and Selection in the Component Palette)
-
In the Property Inspector, set the label to Commissioned? and the Value to #{viewScope.commission}.
-
Drag an Input Date component to the Panel Form Layout.
-
In the Property Inspector, set the label to Starting and the Value to #{viewScope.start}.
-
Expand the SalaryService data control to see the String, which represents the results from the web service.
-
Drag String to the Panel Page and drop it as an ADF Mobile Output Text.
-
First, you want to control the rendering of the Output Text field that holds the results from the web service. To do that, add a condition to the Rendered property. Using the Expression Builder, set the Rendered property to evaluate a new variable, #{viewScope.displayResults == 'Y'}. Click OK.
-
Next, add a setPropertyListener component that sets the value of the viewScope.displayResults variable to Y. To do this, drag a SetPropertyListener component to the SalaryUpgrade button, and set the following properties:
From: #{'Y'}
To: #{viewScope.displayResults}
Type: action -
Finally, you need to do provide a way back to the calling page. Select the first button, which is cb1 and in the Property Inspector, set the Text to Back and the Action to __back.
-
Save your work.
-
Create a default empty page for the TakePicture view activity using the default values. (HINT: Open EmpsTaskFlow, double-click TakePicture and click OK to accept the default values for the page.)
-
Save your work.
-
From the Application menu in JDeveloper, select Deploy Anfroid2 to Android emulator.
-
In the Deployment tab of the Log window, make sure the deployment is finished.
-
Remember that the SalaryUpgrade web service needs to be running for the application to work. The instructions for running the web service are in step 2 of this tutorial.
-
In the emulator, or your device, navigate to the Applications page and open the Emps application.
-
Click the right-arrow on the left side of the page to show the list of employees.
-
Click Shay (or any of the employees in the list) to select an employee.
-
Click the Update button. The application now shows the SalaryUpgrade page.
-
Using the Android Emulator UI, change the salary to 5555, set the Commission to On, and change the Start Date to a few days from today.
-
Click SalaryUpgrade. Notice the message that appears under the SalaryUpgrade button. This message is returned from the SalaryUpgrade web service. Your application has successfully called a web service and displayed the returned values.
Next, you will design the second page, SalaryUpgrade which you will use to consume the web service.
There will be two parts to this page. The first part will show the employee data for the currently selected row. The second part will be used to invoke the web service.
This data control and bindings will show employee data, but you need to make sure that the page displays the data of the currently selected row. To select the current row, you add a call to a method that will set the row.
Now that you have the action binding, you need to add it to the list of executables.
In the next few steps, you add the components that call the web service.
The Salary Upgrade web service accepts the following parameters; Name, Date, Salary, and Commission. Name and Salary are fields on the form you just added. Therefore, when you call the the web service, you pass the Name and Salary from the fields on that form.
For the next two parameters you set the values to viewScope variables you populate later.
As you have seen, the SalaryUpgrade web service accepts four parameters. The first two values come from the form you created from the emps data control. That leaves two more values that need to come from somewhere. You have already set the bindings on the SalaryUpgrade method call to use the two form fields. Now you need to create fields to accept the two additional parameter values (date and commission) and store those values in the viewScope parameters that you created.
That takes care of the parameter values passed to the web service, but we also want to show the results from the web service.
At this point, the page is complete and would run. However because the output field is based on a call to the web service, the page will call the web service before the user can enter the start date or the commission value. In the next few steps you set the page to call the web service only after the SalaryUpgrade button is clicked.
As a result of the previous few steps, when the user enters values in the commission and date fields and clicks the SalaryUpgrade button, the page calls the web service and displays the results.
In preparation for the completed application, you created a view activity on EmpsTaskFlow called TakePicture. In Part 3 of this tutorial, you will use that view activity to use device services. However, before you can deploy the application in this part of the tutorial, you need to create a page as a place holder for that view activity.
Next, deploy and test the application
The emulator now shows the Emp List page which is the entry page to your application.
You have now successfully added ADF controls to your application that consume a web service. In the next section of this tutorial, you integrate some native device features into your application.