Articles
Application Development Framework
Developing for the Apple iPhone with Oracle JDeveloper and ADFby Joe Huang Any developer can rapidly create a compelling iPhone Web app today, using Oracle JDeveloper and ADF. Published December 2008 The Apple iPhone, since its initial introduction in July 2007, has become the fastest selling smartphone in the 18 months of its existence. A key factor in its success is its powerful Safari Web browser that allows users to view virtually any page on the Web, with full support of JavaScript and AJAX features typically found on desktop browser only. This article will focus on using Oracle JDeveloper and Oracle Application Development Framework (ADF) Mobile to develop a mobile Web application optimized for the iPhone. ChallengesDesigning a Web application varies greatly for a mobile user who accesses the Web using the 3.5-inch iPhone screen, versus for a sedentary user access the Web using a 22-inch LCD monitor. This offers an interesting challenge to Web developers, since Web development tools on the market today fit into one of these two categories:
The Oracle ADF Mobile Browser client, however, enables developers to leverage the AJAX capabilities of the iPhone Safari browser, while maintain complete compatibility with mobile browsers that can only handle plain HTML or WAP 2.0 contents. Furthermore, it helps developers create user interfaces that are optimized for iPhone screen size and mobile Web use. Mobile Development Basics in Oracle ADFOracle ADF supports mobile application development through Oracle ADF Mobile. The cores of mobile support reside in the JavaServer Faces (JSF) mobile render kits delivered through MyFaces Trinidad components, as well as in Oracle JDeveloper design time support. Here are just some of the key features delivered by ADF Mobile:
Developing an Oracle ADF Mobile Application Optimized for iPhoneHigh level steps to develop an iPhone-optimized mobile application using Oracle ADF and JDeveloper are as follows:
Adding iPhone Resolution to the View EditorScreen resolutions list in the View Editor provides a visual aid for developers when designing views. Oracle JDeveloper provides support for the following resolutions out-of-box: 240x240, 240x260, 240x320, and 320x240. iPhone supports a 320x480 resolution. To add iPhone resolution to the View Editor:
Achieving iPhone Native Look-and-FeelSkinning allows an Oracle ADF Mobile application to take on iPhone native look-and-feel using Trinidad components. Furthermore, it allows the same set of UI components to take on platform native look-and-feel, without needing to create multiple versions of the same application for different mobile devices. The first step in skinning for iPhone is to implement logic that would allow a JSF application to apply different style sheets for different mobile browsers during run time. Typically an Oracle ADF Mobile application needs to support more than one type of devices, and it would be impractical to define a style sheet that works well across multiple devices. To do that, first a Managed Bean should be created for the page flow of the application, where one of the methods needs detect the browser type, and return the name of the skin family that will be used for that platform. This method would be invoked in the Trinidad-config.xml file; for example:
<skin-family>#{AgentUtil.phoneFamily}
Where AgentUtil is the class name of the Managed Bean, and phoneFamily is the method that returns the skin family as a string. The various skin families are defined in the Trinidad-skins.xml file, as well as the corresponding location of the CSS file within the project. For example, for iPhone, skin family can be defined as:
<skin>
The AgentUtil.phoneFamily method would return iphoneFamily when iPhone is used. This would cause the style sheet located at styles/iPhone.css to be used. A sample code snippet for the AgentUtil.phoneFamily method is shown below; please note that the sample code only contain cases for iPhone, Symbian, and all other mobile browsers. You may add additional browsers as necessary.
private String IPHONE_SKIN = "iphoneFamily";
One note about the function agent.indexOf(“<UA String>”). This function would use the input <UA String> to match against the User Agent field of the browser that's making the request. This function performs a partial match – for example, in the example agent.indexOf(“iPhone”), this function would check the entire User Agent string of the browser against the pattern “iPhone”. If a match is made, i.e. the user agent contains the string iPhone, then the function would be return -1. You may specify as much or as little of the string in this field as necessary, as long as the return guarantees the match you are looking for. While you should specify the UA string that works in your test case, here are some patterns that are commonly used:
Detailed instructions will be published in the next version of Oracle ADF Mobile Developer Guide . Further details of how to define CSS files for Trinidad-based application, please refer to this doc. Implementing Common iPhone UI Elements Using Skinning and Trinidad ComponentsThe next step is to achieve the iPhone native look-and-feel is to define the style classes in the style sheet that would support the creation of common iPhone UI components. There are basically three common UI elements around in an iPhone native application: Navigation Panel Lists, Field Set Panel, and Navigation Bar. Let's look at each of these elements in more detail. Navigation Panel ListsNavigation Panel Lists displays a list of data as a one column table, where each row contains data from multiple columns. It supports the scenario where a user browser through a list of summary data, and select a row to reveal additional detail associated with that row. In the example below, the Panel List displays a list of houses on sale.
<div class="panelBase">
For the definition of the style classes such as listingImage, please use
this link to download a sample iPhone CSS file.
Field Set PanelField Set Panel is typically used to display detailed information about an instance of data, and may provide links that navigates to another screen or view that displays related detailed information. An example of the Field Set Panel is as follows; following the example above, this view displays detailed information about a house, as well as links to additional details about the house:
<div class="panelBase">
Note that the panelBase style provides the pin-strip background of this screen. The two panelCaptionGroup controls breaks the display of data into two groups. Lastly, the street field is a tr:goLink component that can invoke iPhone Google Maps application. This functionality will be explained in the next section.
For the definition of the style classes such as listingImage, refer to the sample iPhone CSS file. Navigation BarNavigation Bar provides the primary navigation mechanism for an iPhone application. In previous examples, navigation bar is located on the top of the screen, and provides finger-clickable buttons that would bring up another view. Let's look at the navigation bar in more detail:
<tr:panelHeader text="Details" styleClass="toolbar" rendered="true">
Again, the definition of the style classes such as listingImage can be found in the sample iPhone CSS file.
Interacting with iPhone ServicesMobile device browsers typically provide a couple of basic interaction with on-device services, such as telephony functionality and email functionality. iPhone takes it one step further by adding interaction with iPhone Google Maps application. Leveraging these functionality using Oracle ADF and JDeveloper takes just a few lines of code. With easy access to the binding layer where data such as phone number and address resides, Oracle ADF and JDeveloper makes it very easy to allow users to, say, dial a phone number residing in a database field. Telephony ServiceiPhone Safari has built in capability of recognizing phone numbers on a page, and allows user to click and dial on that number. This capability does not always work, however. If a phone number is simply displayed in an outputText field, there is no guarantee that iPhone will recognize it as a phone number. To ensure that iPhone recognizes a phone number, developer should display the phone number in a tr:goLink component, and add tel: to the destination attribute of goLink. The sample code to dial a phone number contained in the session variable houseDetails and field AgentPhone:
<tr:goLink styleClass="messageLink"
Additionally, iPhone provides partial support for the RFC 2086 protocol, so it is possible, for example, to dial a phone number, pause for a few seconds, and then dial an extension. The phone number may also contain letters, which would cause iPhone to dial corresponding number for these letters. To illustrate this point, let's look at this sample code with a fake phone number:
<tr:goLink styleClass="messageLink"
This would cause iPhone to dial 1-800-873-5338, wait for 2 seconds (pp), and then dial 8.
Email ClientiPhone Safari browser provides interface to iPhone email client as well. To invoke the email client with an email destination filled out, developer would use a tr:goLink component to display the email field, and add mailto: to the destination attribute of the component, such as:
<tr:goLink styleClass="messageLink"
When a user links on this goLink, iPhone Email client will be started, and the To: field would be populated with the content of the AgentEmail variable.
iPhone supports population of other email fields as well. The developer would simply append the following to the destination attribute of the goLink component:
For example, the following code would pre-populate an email with a subject, cc recipients, and message text:
<tr:goLink styleClass="messageLink"
iPhone Google MapsiPhone Safari browser can intercept calls to http://maps.google.com, and invoke the Google Maps application on the iPhone instead. There are partial supports for dropping a pin at a specified address in the Google Maps application. Once the pin is dropped, iPhone user can use GPS and “getting directions” functionality to navigate to that address, and even look at what the address looks like at the street level. To access this functionality, developer would use tr:goLink component, and populate the destination attribute of the goLink component with an URL to Google Maps and the address. The Google Maps URL needs to be in this format:
http://maps.google.com/maps?q=<Address_Field>
For example, the following will drop a pin at a location specified by session variables houseDetail.Street, houseDetail.City, and houseDetail.Zip.
<tr:goLink styleClass="messageLink"
It is also possible to program driving directions using this feature. The format of the Google Maps URL would be:
http://maps.google.com/maps?saddr=<Start_Address>&daddr=<destination_address> </destination_address>This is a very powerful feature; it allows ADF and JDeveloper developers to invoke driving directions functionality with just a few lines of code. A user can simply click on a link on an ADF Mobile view to get location or driving directions through Google Maps functionality. ConclusioniPhone has re-defined "ease of use" for mobile devices; almost anyone can easily pick it up and use it without extensive training. The reason for that is no secret: the user interfaces of iPhone's core applications work perfectly with the device hardware. Any other application running on the iPhone will need to adhere to that user interface standard, or the user will lose the "ease of use advantage" when using that application. In thius article, you learned how easily such a user interface can be developed using Oracle ADF and JDeveloper, so any developer can rapidly create a compelling iPhone Web App today. More Resources for Getting Started NowThe following resources will help to get started on iPhone development using ADF and JDeveloper today:
Joe Huang is the product manager for Oracle ADF Mobile. |
||||||||||||||||||||||||||||||||||||||||||||||