Skip to main content

ADF Mobile : Your First Navigation and Device Interaction

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 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.
 <amx:facet name="header"/>  
 <amx:outputText value="Take picture of #{pageFlowScope.row.firstname} #{pageFlowScope.row.lastname}" id="ot1"/>  
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"  
 <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"/>  
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 component.
 <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=""></a>" xmlns:amx="<a href=""></a>"  
 xmlns:dvtm="<a href=""></a>">  
 <amx:panelPage id="pp1">  
  <amx:facet name="header">  
    <amx:outputText value="Take picture of #{pageFlowScope.row.firstname} #{pageFlowScope.row.lastname}" id="ot1"/>  
  <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"/>  
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.


Amar said…
hi luc,

Thanx for this excellent post!!

Please provide this example project,so that it will useful for beginners like me

Amar said…
hi luc,

Thanks for this excellent post!!

Please provide this example project so that it is very useful for beginners like me!!

Anonymous said…
HI Bors,
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

Popular posts from this blog

ADF 12.1.3 : Implementing Default Table Filter Values

In one of my projects I ran into a requirement where the end user needs to be presented with default values in the table filters. This sounds like it is a common requirement, which is easy to implement. However it proved to be not so common, as it is not in the documentation nor are there any Blogpost to be found that talk about this feature. In this blogpost I describe how to implement this.

The Use Case Explained
Users of the application would typically enter today's date in a table filter in order to get all data that is valid for today. They do this each and every time. In order to facilitate them I want to have the table filter pre-filled with today's date (at the moment of writing July 31st 2015).

So whenever the page is displayed, it should display 'today' in the table filter and execute the query accordingly. The problem is to get the value in the filter without the user typing it. Lets first take a look at how the ADF Search and Filters are implemented by the f…

ADF 11g Quicky 3 : Adding Error, Info and Warning messages

How can we add a message programatically ? Last week I got this question for the second time in a months time. I decided to write a short blogpost on how this works.

Adding messages is very easy, you just need to know how it works.
You can add a message to your faces context by creating a new FacesMessage. Set the severity (ERROR, WARNING, INFO or FATAL ), set the message text, and if nessecary a message detail. The fragment below shows the code for an ERROR message.

1: public void setMessagesErr(ActionEvent actionEvent) {
2: String msg = "This is a message";
3: AdfFacesContext adfFacesContext = null;
4: adfFacesContext = AdfFacesContext.getCurrentInstance();
5: FacesContext ctx = FacesContext.getCurrentInstance();
6: FacesMessage fm =
7: new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, "");
8: ctx.addMessage(null, fm);
9: }

I created a simple page with a couple of buttons to show the result of setting the message. When the butto…

How to: Adding Speech to Oracle Digital Assistant; Talk to me Goose

At Oracle Code One in October, and also on DOAG in Nurnberg Germany in November I presented on how to go beyond your regular chatbot. This presentation contained a part on exposing your Oracle Digital Assistant over Alexa and also a part on face recognition. I finally found the time to blog about it. In this blogpost I will share details of the Alexa implementation in this solution.
Typically there are 3 area's of interest which I will explain. Webhook Code to enable communication between Alexa and Oracle Digital AssistantAlexaDigital Assistant (DA) Explaining the Webhook Code The overall setup contains of Alexa, a NodeJS webhook and an Oracle Digital Assistant.
The webhook code will be responsible for receiving and transforming the JSON payload from the Alexa request. The transformed will be sent to a webhook configured on Oracle DA. The DA will send its response back to the webhook, which will transform into a format that can be used by an Alexa device. To code exposes two REST …