Tuesday, February 19, 2013

Usage of User Preferences in ADF Mobile

Preferences enable you to add settings that can be configured by end users. In this article will see how to use adfmf:preferenceList to change the display name format setting in the Contacts list at run time.

 ADF Mobile supports application-level and application feature-level user preference pages, in this demo I'm using application feature-level user preference page. Preferences are populated with default values at startup. These values are defined in the adf-feature.xml file, on load of application user can click on preferences feature in navigation bar and select the display name format to be displayed.

Application screen looks like below when it deployed and run on Android Device/Emulator. Displays the Contacts list on the screen.


Click on the menu button, this will launch the Navigation Bar with Preferences, Hide Navigation and SpringBoard options. Click on Preferences.


In Contact Preference Screen, clicking on Name Display will open the popup by displaying Name Display formats which are defined in adf-feature.xml  file. Now select "LastName FirstName".


I found the way to refresh the Contacts list in the screen, so striking of the below section. Here user don't need to click on the refresh button, after clicking on the device back button will refresh the contact list.

Next click on the device back button will take you to the Contacts screen, notice here data will be displayed in the old format only "FirstName LastName". Here clicking of the device back button handler should be provide to refresh the Contacts list on the screen. I didn't find any ways to refresh list after back button action, so filed the bug against this once I get the solution will update the article. Time being as a workaround provide refresh button, after clicking on refresh button Contacts list will be redraw with updated name display format.


You can download the sample workspace from here. In below section I will not provide all the steps to create the application, only key ones are shown. Above sample download workspace doesn't have extended lifecycle listener class, please follow the below steps to create LifeCycleListener for fetaure.

By design, for a feature to be informed of Device Actions that are sourced from outside of that feature that feature must have a lifecycle listener. Follow the below steps.
  1. Add new Java Class
  2. Set Name and package as desired
  3. Click '+' under Optional Attributes to add an interface
  4. Choose the interface LifeCycleListener (oracle.adfmf.feature),  Save (no other changes to default class contents need to be made for this) 

Next Open the adfmf-feature.xml and map ExtendedFetureLifeCycleListener.java to LifeCycle Event Listener as shown below.


Use the adfmf:preferences element to create the preferences in adf-feature.xml file as below.
<adfmf:feature id="Preference" name="Preference">
 <adfmf:content id="Preference.1">
  <adfmf:amx file="Preference/ContactList.amx"/>
 </adfmf:content>
 <adfmf:preferences>
  <adfmf:preferenceGroup id="Pref1" label="Contact Preference">
   <adfmf:preferenceList id="Pref1NameDisplay" label="Name Display" default="NF1">
    <adfmf:preferenceValue name="FirstName LastName" value="NF1"/>
    <adfmf:preferenceValue name="LastName FirstName" value="NF2"/>
   </adfmf:preferenceList>
  </adfmf:preferenceGroup>
 </adfmf:preferences>
</adfmf:feature>

In ContactList.amx page access the preference values using EL expression and ternary operator is used the switch between the display names.
#{preferenceScope.feature.Preference.Pref1.Pref1NameDisplay eq 'NF1' ? row.firstLastName : row.lastFirstName}"

7 comments:

  1. Deepak, I recently was looking at ADF for full time use. I got confused looking at the licensing and what would be my obligation to Oracle. I realize it's not open source and that's fine but I want to know where I stand. Would someone PLEASE write a License explanation for ADF for Dummies. Thanks!

    ReplyDelete
    Replies
    1. Bob,

      ADF Mobile is licensed as part of the Oracle Application Development Framework (ADF). Oracle ADF can be licensed either as “Oracle Application Development Framework and TopLink” item on the technology price list, or as part of the Oracle WebLogic licenses.

      A named user plus license of ADF will entitle customer a single named user license of the ADF Mobile. A processor license of ADF will allow customer to deploy ADF Mobile-based application to unlimited number of devices.

      You can find more clarifications on ADF Mobile related - http://www.oracle.com/technetwork/developer-tools/adf/learnmore/adfmobilefaq-1866697.pdf

      Delete
  2. Open source adf mobile if you want adoption if not who would use it? Its already up hill battle since its behind other webMobile solutions

    ReplyDelete
  3. Hi Anonymous.

    Why should open sourcing contribute to the adoption of ADF Mobile in any way? Do you want to contribute to the source and further development of ADF? I think what you really mean is: "Make it free, I don't want to pay for it". "Free" and "open source" are basically two different concepts. For your information: Anyone with a (payed) support contract can get the ADF sources from Oracle. So in fact, the ADF sources are as open as can be.

    And can you specify why you think ADF is behind other webmobile solutions? Which features from other frameworks are lacking in ADF Mobile?

    ReplyDelete
  4. Hi,

    Is the navigation bar show/ hide controlled through device menu ? Also any way we can customize the navigation bar ie.change number of columns or a different navigation bar depending on the page?

    -Ammalu

    ReplyDelete
  5. sach a great informative post, i really like it.mobile phones

    ReplyDelete
  6. Sach a nice blog with beautiful post, i really like your post. keep it up.324g mobiles

    ReplyDelete