Now ADF Mobile is generally availble, it is now time to create your first ADF Mobile application. In this post I will show you how to create a simple application that contains of two pages with navigation. A bonus for this post is that you will see how to get a picture from the filesystem (or by using the device camera) from within your ADF mobile application
Getting started
To work with ADF mobile you need to download the JDeveloper 11.1.2.3 and the ADF mobile extension and install both. After installing JDeveloper and adding the ADF Mobile extension, you will be able to create a new ADF Mobile Application. In the new gallery you wil find the ‘Mobile Application’ under the applications node.
Accept all the defaults and the JDeveloper application is created for you. What you see are two projects. One called the application controller, and a second one, the viewController. JDeveloper also adds application-level and project-level artifacts.
The applicationController contains several artefacts such as the Datacontrol definition, files for skinning, and a class called LifeCycleListenerImpl. This class can be used to add your own functionality during the different stages of the application life cycle. In the viewController you only see a file called adfmf-feature.xml. This file is used to add, remove, or edit the application features embedded within the mobile application. At an application level, the adfmf-application.xml file is created, which enables you to configure the mobile application.
You will also find application level files that are created for you such as platform specific images for splashscreens and application icons. These can be customized.
That is all you need to get started, and luckily, it is all created for you.
Your first simple ADF Mobile Application
Lets create a two simple java classes to be our data provider.
and ...
Now create a datacontrol based on the Contacts class.
With the datacontrol in place, it is now time to create the page that will use the Contact collection.
Creating features, taskflows and pages
Go to the adfmf-feature.xml file in order to add a new feature. This can be done by clicking the plus icon. For now, lets call this feature ‘contacts’.
This only adds an entry in the xml file, but the actual page or taskflow implementing the feature is not created. This is also an action that can be done from within the adfmf-feature.xml file. By clicking the plus icon (you must be on the content tab for the feature) you can pick either AMX page or taskflow. Choose taskflow and continue.
The taskflow editor now appears with the empty newly created taskflow. Now it is time to add view activities to the taskflow. If you are familiar with ADF development, this the exact same approach as if you were building a ‘regular’ ADF application. Just drag the viewactivities from the component pallet onto the taskflow diagram and add navigation between them. In this case I created two viewactivities. One to show the list, and a second on create a picture of the selected contact.
Creating the pages
The next step is creating the actual pages. This can be done by doubleclicking the view activities on the taskflow diagram. Start with the list page. In the create page wizard, uncheck ‘both’ action checkboxes. There is no need got these now.
On the list page it makes sense to show the content in a ‘List’ layout. With ADF Mobile and JDeveloper you can create this exactly the way you want. Drag and drop the contact collection from the datacontrol onto the page and select ‘ADF Mobile List View’ from the context menu.
In the ListView gallery you can pick from a lot of different Lists, but for now, just stick with the default. For the list view only display the last name. No need for the firstname, however, if you really want to….. just add it. The result should look somewhat like this:
This page will work if all went according to plan. The next step is to add navigation to the second page.
Adding navigation
In order to navigate to the second page, and to see the selected trainee on this second page you need to do two things. The page needs to know when to navigate. For that, we can use the action property of the component. Change the action property to “add” which corresponds to the navigation case defined in the taskflow. Either type it, or select it from the dropdown.
Next make sure that the selected row is made available on the second page. For this a setPropertyListener can be used (Hey, you already knew that from your ADF experience). Set the from property to #{row}, and the to property to #{pageFlowScope.row}.
Now create the second page by doubleclicking on the viewactivity in the taskflow editor, or via invocing the new gallery and pick create new ADF Mobile Page (AMX). In the header facet the #{pageFlowScope.row} reference can be used to display the whole name of the selected contact.
Now create the second page by doubleclicking on the viewactivity in the taskflow editor, or via invocing the new gallery and pick create new ADF Mobile Page (AMX). In the header facet the #{pageFlowScope.row} reference can be used to display the whole name of the selected contact.
component.
<amx:facet name="header"/>
<amx:outputText value="Take picture of #{pageFlowScope.row.firstname} #{pageFlowScope.row.lastname}" id="ot1"/>
<;/amx:facet>;
Creating the picture
This page will be used to take a picture of the contact. This looks pretty complicated but as a matter of fact, it is very straightforward. ADF Mobile ships with a deviceFeature datacontrol. On of the operations in here is the ‘getPicture’. Drag this operation from the datacontrol onto your page, and drop it as a ADF Mobile Button.
In the Edit Action Binding set destinationType to 1 so the image is returned as a fileName, and specify width and height for the image.
You might want to play with the sourcetype. On a simulator this makes no sense, but on an actual device you can invoke the camera by setting sourceType = 1.
An action binding is added to the corresponding pagedefinition file. Again, you already know this from regular ADF development.
<methodAction id="getPicture" RequiresUpdateModel="true" Action="invokeMethod" MethodName="getPicture"
IsViewObjectMethod="false" DataControl="DeviceFeatures"
InstanceName="data.DeviceFeatures.dataProvider"
ReturnName="data.DeviceFeatures.methodResults.getPicture_DeviceFeatures_dataProvider_getPicture_result">
<NamedData NDName="quality" NDType="int"/>
<NamedData NDName="destinationType" NDValue="1" NDType="int"/>
<NamedData NDName="sourceType" NDType="int"/>
<NamedData NDName="allowEdit" NDType="boolean"/>
<NamedData NDName="encodingType" NDType="int"/>
<NamedData NDName="targetWidth" NDValue="150" NDType="int"/>
<NamedData NDName="targetHeight" NDValue="200" NDType="int"/>
</methodAction>
Now drop the returnvalue of the getPicture from the datacontrol on your page as an outputtext. Remove that textfield immediately. The Dnd action was only nessecary in order to create a binding for this returnvalue. It can now be used as the source for an <amx:image id="file" source="#{bindings.Return.inputValue}"/>
Finally add a button to navigate back to the list page. The page would look like this:
<?xml version="1.0" encoding="UTF-8" ?>
<amx:view xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>" xmlns:amx="<a href="http://xmlns.oracle.com/adf/mf/amx">http://xmlns.oracle.com/adf/mf/amx</a>"
xmlns:dvtm="<a href="http://xmlns.oracle.com/adf/mf/amx/dvt">http://xmlns.oracle.com/adf/mf/amx/dvt</a>">
<amx:panelPage id="pp1">
<amx:facet name="header">
<amx:outputText value="Take picture of #{pageFlowScope.row.firstname} #{pageFlowScope.row.lastname}" id="ot1"/>
</amx:facet>
<amx:commandButton actionListener="#{bindings.getPicture.execute}" text="getPicture" disabled="#{!bindings.getPicture.enabled}" id="cb1"/>
<amx:image id="file" source="#{bindings.Return.inputValue}"/>
<amx:commandButton action="return" text="List" id="cb2"/>
</amx:panelPage>
</amx:view>
Deploying and testing
Before being able to test the application you need to create a deployment profile. Go to your application properties and select “new deployment profile” and create one for ADF Mobile for iOS. Accept the defaults for now.
Now you can deploy the application to an iOS simulator or device.
After deploying to an iOS simulator the application works. Click on the application icon to start the application. The app starts and you will see the list view. Click (or tab on a real device) on one of the names in the list view. The Picture view opens empty with the name of the selected contact in the header. Now you can invoke the getPicture button. .
On a real device the camera can be invoked if you would set sourcetype = camera (or 1), on the simulator, you get to pick an image from the gallery. After taking the picture (or selecting it), the image displays in the application, right where we want it.
I created this application on a Macbook so I can use the iOS simulator to run the application. However, the exact same application will run on an iPhone, iPad if you deploy it to the device instead of deploying it to the simulator. And it will also run on Android devices. The only thing you need to do is create a deployment profile for Android and deploy to the actual device.
Footnote
This blogpost (originally posted on the amis technology blog) is created under the assumption that you have already installed all SDK’s for Android Development, and the xCode for iOS development. Also all settings for Android and iOS development in JDeveloper need to be set and point to the android SDK and xCode locations. Running on Android Simulators is extemely slow, so you will probably need to connect your device and deploy to it in order to test your application. I will propbably write more on these topics in the near future.
Comments
Thanx for this excellent post!!
Please provide this example project,so that it will useful for beginners like me
Regards
Amar
Thanks for this excellent post!!
Please provide this example project so that it is very useful for beginners like me!!
Regards
Amar
Thanks for the Nice tutorial,
I have to do validation( client side validation) for input text fields in amx pages can you please let me know how to do it with an example