ADF Mobile Code Corner

Similar documents
ADF Mobile Code Corner

ADF Code Corner. 70. How-to build dependent list boxes with Web Services Business Services. Abstract: twitter.com/adfcodecorner

ADF Mobile Code Corner

ADF Code Corner How-to enforce LOV Query Filtering. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to declaratively build a master-detail behavior with DVT components. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to bind custom declarative components to ADF. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to further filter detail queries based on a condition in the parent view using ADF BC. Abstract: twitter.

ADF Code Corner. 65. Active Data Service Sample Twitter Client. Abstract: twitter.com/adfcodecorner

ADF Code Corner. 90. Filtering ADF bound lists. Abstract: twitter.com/adfcodecorner

ADF Code Corner. 64. How-to implement a Select Many Shuttle with pre- selected values. Abstract: twitter.com/adfcodecorner

ADF Mobile Code Corner

ADF Code Corner. 97. How-to defer train-stop navigation for custom form validation or other developer interaction. Abstract: twitter.

ADF Code Corner How to cancel an edit form, undoing changes with ADFm savepoints

ADF Code Corner How-to use the af:autosuggestbehavior component tag with ADF bound data sources. Abstract: twitter.

ADF Code Corner How-to build a reusable toolbar with Oracle ADF Declarative Components. Abstract: twitter.com/adfcodecorner

ADF Code Corner How-to launch a popup upon rendering of a page fragment in a region using JSF 2. Abstract: twitter.

ADF Code Corner. 016-How-to customize the ADF Faces Table Filter. Abstract: twitter.com/adfcodecorner

ADF Code Corner Implementing auto suggest functionality in ADF Faces. Abstract:

ADF Code Corner How-to restrict the list of values retrieved by a model driven LOV. Abstract: twitter.com/adfcodecorner

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

ADF Code Corner. 71. How-to integrate Java Applets with Oracle ADF Faces. Abstract: twitter.com/adfcodecorner

ADF Mobile : Data Services Java Beans. Ma Ping

ADF Code Corner. 048-How-to build XML Menu Model based site menus and how to protect them with ADF Security and JAAS. Abstract:

ADF Hands-On. Understanding Task Flow Activities / 2011 ADF Internal Enterprise 2.0 Training. Abstract:

ADF Code Corner How-to show a glasspane and splash screen for long running queries. Abstract: twitter.com/adfcodecorner

CIS 764 Tutorial: Log-in Application

Oracle Fusion Middleware 11g: Build Applications with ADF Accel

Customizing Oracle Identity Governance: Populating Request Attributes

Getting Started with Web Services

Oracle Fusion Middleware

Getting Started with Web Services

<Insert Picture Here> How to Debug Oracle ADF Framework Applications

User s Guide 12c (12.2.1)

Take Your Oracle Forms on the Road Using ADF Mobile. Mia Urman, OraPlayer & Denis Tyrell, Oracle Corporation

NetBeans IDE Field Guide

Oracle Retail Accelerators for WebLogic Server 11g

ADF Code Corner. Oracle JDeveloper OTN Harvest 02 / Abstract: twitter.com/adfcodecorner

Oracle Developer Day

Oracle Fusion Developer Guide (ISBN: ) Preview Chapter 1. The Quick Lerner s Guide to Oracle Fusion Web Application Development PREVIEW

Oracle Developer Day

Oracle Fusion Middleware

IBM. Application Development with IBM Rational Application Developer for Web Sphere

Active Endpoints. ActiveVOS Platform Architecture Active Endpoints

Quick Web Development using JDeveloper 10g

Contents I Introduction 1 Introduction to PL/SQL iii

Java EE 7: Back-End Server Application Development

Oracle Enterprise Pack for Eclipse

Oracle Fusion Middleware

Oracle BPEL Process Manager Demonstration

Oracle Fusion Middleware 11g: Build Applications with ADF I

ADF Region Interaction: External Train Navigation

An Oracle White Paper March Introduction to Groovy Support in JDeveloper and Oracle ADF 11g

Building Rich Enterprise JSF Applications with Oracle JHeadstart for ADF (11.1.1)

Oracle JDeveloper/Oracle ADF 11g Production Project Experience

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

ADF Code Corner. Oracle JDeveloper OTN Harvest 01 / Abstract: twitter.com/adfcodecorner

How to Develop a Simple Crud Application Using Ejb3 and Web Dynpro

Oracle Middleware 12c: Build Rich Client Applications with ADF Ed 1 LVC

ADF Code Corner How-to use Captcha with ADF Faces and Oracle ADF. Abstract: twitter.com/adfcodecorner

Vendor: Oracle. Exam Code: 1Z Exam Name: Oracle Database 11g: Program with PL/ SQL. Version: Demo

Supports 1-1, 1-many, and many to many relationships between objects

Managing Your Database Using Oracle SQL Developer

Efficient Object-Relational Mapping for JAVA and J2EE Applications or the impact of J2EE on RDB. Marc Stampfli Oracle Software (Switzerland) Ltd.

1 Copyright 2011, Oracle and/or its affiliates. All rights reserved.

Oracle Exam 1z0-441 Oracle Mobile Development 2015 Essentials Version: 6.0 [ Total Questions: 85 ]

Oracle Identity Governance 11g R2 PS1 - Creating a Parallel Approval Process

Oracle Fusion Middleware 11g: Build Applications with ADF I

Just Get It Written: Deploying Applications to WebLogic Server Using JDeveloper and WLS Console Hands on Practice

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

1Z0-441

<Insert Picture Here> Advanced ADF Faces. Frank Nimphius Principal Product Manager

JBoss SOAP Web Services User Guide. Version: M5

ADF OAF Who Cares? You Do! Oracle Applications Framework / Application Development Framework - Which way do I go?

CO Java EE 7: Back-End Server Application Development

Building J2EE Applications with Oracle JHeadstart for ADF

ADF Desktop Integration 11g Release1 Component and Feature Demo

Oracle Web Service Manager 11g Component Level Role Authorization (in SOA Suite) March, 2012

ORACLE JHEADSTART 12C for ADF

Oracle Fusion Middleware

User Guide Using AuraPlayer

Oracle ADF 11g: New Declarative Validation, List of Values, and Search Features. Steve Muench Consulting Product Manager Oracle ADF Development Team

Skyway Builder 6.3 Reference

USER GUIDE Azure Factory

MyEclipse ER-Designer Quickstart

Mobile Application Development: Introducing ADF Mobile Native Client Framework

Creating a SQL Service with IBM WebSphere Portlet Factory. Introduction to creating services from a relational database

Oracle Fusion Middleware

Java EE Architecture, Part Three. Java EE architecture, part three 1(57)

Real Life ADF Mobile. 10 things that you don't get from the developer guide

Orgnazition of This Part

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

Oracle ADF: The technology behind project fusion. Lynn Munsinger Principal Product Manager Application Development Tools Oracle Corporation

Using SQL Developer. Oracle University and Egabi Solutions use only

Including Dynamic Images in Your Report

Build a Mobile App in 60 Minutes with MAF

ER/Studio Enterprise Portal User Guide

HIBERNATE MOCK TEST HIBERNATE MOCK TEST IV

Appendix C: Run a Report of Individual Listings for your Department

Overview. Principal Product Manager Oracle JDeveloper & Oracle ADF

DB2 Stored Procedure and UDF Support in Rational Application Developer V6.01

Transcription:

ADF Mobile Code Corner m05. Caching WS queried data local for create, read, update with refresh from DB and offline capabilities Abstract: The current version of ADF Mobile supports three ADF data controls: Web Service, REST Service and POJO. When working with the WS and REST data control it is recommended practices to access the service throuh the WS and REST data control but to expose the data through the POJO data control to the UI. The advantage of such an architecture is better control for filtering and manipulating WS queried data, as well as a better performance when working with data on the mobile device. In this article I explain how you query data from a SOAP Web Service, how you save the data in on device local entities and how to write local data back to the WS. In the provided sample, you find hookpoint to change for using a local SQLite database instead of an object cache for persistence. twitter.com/adfcodecorner Author: Frank Nimphius, Oracle Corporation twitter.com/fnimphiu 25-APR-2013

Oracle ADF Mobile Code Corner is a blog-style series of how-to documents targeting at Oracle ADF Mobile that provide solutions to real world coding problems. ADF Mobile Code Corner is an extended offering to ADF Code Corner Disclaimer: All samples are provided as is with no guarantee for future upgrades or error correction. No support can be given through Oracle customer support. Please post questions or report problems related to the samples in this series on the OTN forum for Oracle JDeveloper: http://forums.oracle.com/forums/forum.jspa?forumid=83 Introduction For better performance when working with remote services in ADF Mobile, and to ensure data can be updated in offline mode, you want to look into how to cache queried data on the mobile device. This article explains how to use a POJO cache for this and how to access data queried from a WS data control in Java to expose in a POJO data control. The use of the SQLite for offline data use is not in the scope of this article. However, writing and reading cached data to a local SQLite database for offline use and manual synchronization using the ADF Mobile lifecycle listener is quite easy to implement. You find sample code for accessing SQLite in the HR sample that is shipped with the ADF Mobile product. The sample for this ADF Code Corner article uses a POJO data control EmployeesListCache to dipatch between the server side Web Service and the mobile device for handling application read and update use cases. To integrate SQLite, you just hook into the read and write methods getallemployees, getalldepartment, getalljobs and persistupdatedemployeedata. Note: After setting up your development environment you can examine ADF Mobile sample applications located in the PublicSamples.zip file in the <jdev_install>/jdeveloper/ jdev/extensions/oracle.adf.mobile/samples directory on your development computer. This includes the HR sample application. At runtime, the sample application starts with a list view of employees queried through a SOAP service from the employees table of the Oracle HR database sample schema. Once queried, the employee data is cached in a POJO for local read and write operations. The POJO is exposed as a data control for declarative ADF UI-data binding. 2

As shown in the image above, selecting a row in the list performs navigation to an edit page using the ADF task flow. 3

Changing data, as shown in the image above, and pressing Submit will persist the change in the local POJO and then call the Web Service to also persist the change in the database. Note: Instead of persisting the change in the POJO and the database you could also use the SQLite database and defer server side persistence to a later point in time. This however is not part of the demo you can download for this article. Pressing the Refresh button will delete the local POJO csache and re-query the data from the database so that changes added to the database are becoming visible on the mobile. Configuring the Web Service for this Sample The ADF Code Corner mobile sample for this article queries data from the Oracle HR schema. The HR schema is accessed by an EJB model that is exposed as a SOAP Web Service. The Web Service project is provided as a separate JDeveloper 11.1.2.3 workspace so it can be deployed to the integrated WLS server. Open the Web Service workspace in JDeveloper by choosing File -> Open in Oracle JDeveloper 11.1.2.3 and navigate to the directory in which you unzipped the downloaded sample. Select the HrServices.jws file in ADFCodeCornerSamples -> HrService folder and press Open. To configure the database access for the Web Service you need to switch to the Database Navigator view. For this, in JDeveloper, select the View -> Database -> Database Navigator menu option. Then expand the HrService entry and select the contained hrconn configuration entry using the right mouse button. 4

Choose Properties from the opened context menu to edit the database connect information as shown in the image below. Keep the name of the connection as hrconn. Use the Test Connection button to test the database connection. If the connection works, continue and run the Web Service in the JDeveloper WS tester. For this, in the Application Navigator, expand the project structure as shown in the image below and right mouse click onto the HrFacadeBean.java file entry. 5

Choose Test Web Service from the context menu like shown in the image below. Dong so, you deploy the Web Service to the integrated WLS in Oracle JDeveloper and start the integrated Web Service tester for testing the service. Note: If this is the first time you start the integrated WLS, a dialog shows for you to define a password for the integrated WLS administrator. Provide the password and keep all settings as defaulted. This way the integrated WLS also listens for the IP address or the domain address of your computer, which needs to be the case for the mobile device to be able to access the service. 6

ADF Mobile Configuration & Deployment The mobile application uses a Web Service data control to access the HR service on the server. The connect information is saved in the connections.xml file that you find in the Application Navigator -> Application Resources -> Descriptors -> ADF META-INF folder in JDeveloper. Double click the connections.xml file to open it in the JDeveloper source editor. Change the localhost references in this file (marked in the image below) to the IP address or the domain name of the machine that runs the HR service. If you use the integrated WLS server in Oracle JDeveloper then you can keep the port to 7101, if not change it as well. With this change (and the previous change of the database connection in the HRService WS project) the application is now ready for device deployment. As shown in the image below, choose the Application - > Deploy -> ANDROID_MOBILE_NATIVE_NoDebug deployment profile to deploy the application to an Android device. If you want to deploy it to an Apple device, create a new deployment profile using the New Deployment Profile option in the same menu. 7

What could go wrong? If you followed the setup instructions then all that could go wrong is: i) You did not download the ADF Mobile extension and because of this the deployment fails. If so, choose Help -> Check for Updates in the JDeveloper menu to download the extension.; ii) You did not configure a keystore to sign the deployment. If so, then have a look at this website, http://docs.oracle.com/javase/tutorial/security/toolsign/step3.html create a keystore and a key entry and configure it for the Android platform in the JDeveloper Tools - > Preferences -> ADF Mobile menu. POJO Caching Explained As mentioned already, the Web Service data is queried through an ADF Web Service Data Control, which is a purely declarative job to create at design time. The Web Service Data Control is then accessed from Java in a POJO - EmployeesListCache - that itself eposes collections read from the WS DC in a data control. The Web Service Data Control The Web Service Data Control is created in the DependentList view controller project and exposes all the method of the SOAP service. The WS Data Control is accessed from the EmployeesListCache class, which then also is exposed as a data control. The WS Data Control structure is shown in the image below. 8

The POJO data control is used in the ADF Mobile AMX page to bind the user interface components to data. As you can see, the names of the exposed methods and collections differ from the names in the WS Data Control, a clear indication that the POJO wraps the WS Data Control. The Client Side POJO Model and WS DC access The POJO accesses the Web Service Data Control using the following code lines private HashMap _findallemployees() { try { //renew all employee data employeelistcache = new HashMap(); //invoke WS data control from this POJO ArrayList parameternames = new ArrayList(); ArrayList parametervalue = new ArrayList() ArrayList parametertypes = new ArrayList(); //Generic representation of a data control's data provider //object. It exposes meta information about the providers //attributes and accessors, as well as the ability to get and set //their values. //This interface abstracts the raw data provider object from the //nature of its type of data control; the raw provider can be a 9

//deserialized representation of an object returned by a SOAP or //REST web service call, or it can be an actual java class //instance. This interface is used primarily by the internals of //the embedded java data control framework, however it can also //be used when invoking data control methods directly from //application java bean code. GenericType employeeslist = (GenericType)AdfmfJavaUtilities.invokeDataControlMethod( "HrWSDC", null, "getemployeesfindall", parameternames, parametervalue, parametertypes); if (employeeslist!= null) { for (int i = 0; i < employeeslist.getattributecount(); i++) { GenericType row = (GenericType)employeesList.getAttribute(i); Employees employee = (Employees)GenericTypeBeanSerializationHelper.fromGenericType(Employees.class, row); employeelistcache.put(employee.getemployeeid(),employee); catch (AdfInvocationException e) { logapplicationmessage(level.severe, "Cannot read data from Web Service \n", ""+ e.getmessage()); return employeelistcache; Code Explained Note that the "HrWSDC" string is the ID of the Web Service Data Control like shown in the DataControls.dcx file or in the Data Control Window. The getemployeesfindall method is the Web Service method that queries all employee data from the Oracle database. The getemployeesfindall method is exposed on the WS DC. The Web Service method doesn't require any parameter argument and therefore empty Lists instances are passed in to this call. The GenericType interface is explained later and and describes a generic representation of the data returned by the Web Service call. The GenericType contains access to all the WS row data attributes The Employees entity is a client side modeling of the entity queried by the server side query. It s a POJO that contains all the attributes queried by the Web Service call and allows you to update the queried data locally. Similar, the DependentList project (the ViewController project in the sample) has entities for the departments (Departments) and jobs (Jobs) data defined. This way department and job information can be displayed in a LOV without the need to issue a query to the Web Service on each LOV call. The image below shows the entity class defined for the Departments data. 10

Note: To change the local cache from POJO to SQLite database, you would change the method above and use SQL commands to insert rows queried from the Web Service to the database. Of course, you can also use both, a POJO cache and the local database, in which case the local database would be used for caching data beyond application re-starts and for create, update and delete operations at runtime. About GenericType The GenricType interface is a generic data representation of the data control data provider object and exposes information about the provider object attributes and accessors. Though mainly used internally by the data controls in ADF Mobile, this interface can be used in custom mobile applications to model the structure of an object to update the server. The GenericType objects are only exposed for SOAP data controls. In this sample, GenericType is used to write employee data back to the server. About GenericTypeBeanSerializationHelper The GenericTypeBeanSerializationHelper helper class provides an easy way for application developers to convert between the ADF Mobile internal GenericType object and user defined POJOs. Updating Server Side Data The update of server side data (through the WS) is the reverse of the reading of remote data. Similar to the read access, the physical entities on the mobile device must be converted into a generic type, which then is passed as an argument to the Web Service Data Control method that updates the server side. Note: The date field in the employee object caused problems which is why I manually created a new instance of GenericVirtualType instead of using one of the helper classes /** * method to call out to the Web Service for persisting changes to * updated or new employee data. This method also changes the employee * data in this local POJO cache. Note that this sample does not check * if a newly created employee exists and instead just updates the * existing record. In a realistic use you would need to check if the * new object matches an existing object and alert the user, or use 11

* two different method for update and create persistence. * * @param emp employee object to persist */ public void persistupdatedemployeedata(object emp) { //get Employees instance from ADF Mobile ConcreteJavaBeanObject //note that ConcreteJavaBeanObject is the object returned from the //ADF iterator as the current row using EL Employees employee = (Employees) ((ConcreteJavaBeanObject)emp).getInstance(); //update the local list with the new data if (employeelistcache == null) { employeelistcache = _findallemployees(); //check for null employee value in case of a new employee if(employee == null){ AdfmfContainerUtilities.invokeContainerJavaScriptFunction ("adf.sample.mobile.list.dc.employeeslistcache", "navigator.notification.alert", new Object[] {"Employee Object cannot be null." + " Update aborted.","", "Employee Object NULL", "Ok"); return; boolean newemployee = false; //check wthere update or new object creation needs to be performed. //If the employee object is not found in the local cache then we //assume it is a new object that needs to be persisted on the //server and added to the local cache. newemployee = this.getemployeebyid( employee.getemployeeid()).length == 0? true : false; try{ ArrayList parameternames = new ArrayList(); parameternames.add("arg0"); //create a new generic type. Note that the order of attributes //must match the order in the Web Service //Define a metadata object model of the entity structure GenericVirtualType gvt = new GenericVirtualType(); "commissionpct",double.class); 12

"departmentid",long.class); "email", String.class); "employeeid",long.class); "firstname", String.class); "hiredate", Date.class); "jobid", String.class); "lastname", String.class); "managerid",long.class); "phonenumber", String.class); "salary",double.class); //copy values of the updated row object into a generic type to //post to the Web Service gvt.setattribute("commissionpct",employee.getcommissionpct()); gvt.setattribute("departmentid",employee.getdepartmentid()); gvt.setattribute("email", employee.getemail()); gvt.setattribute("employeeid",employee.getemployeeid()); gvt.setattribute("firstname", employee.getfirstname()); gvt.setattribute("hiredate", employee.gethiredate()); gvt.setattribute("jobid", employee.getjobid()); gvt.setattribute("lastname",employee.getlastname()); gvt.setattribute("managerid",employee.getmanagerid()); gvt.setattribute("phonenumber",employee.getphonenumber()); gvt.setattribute("salary",employee.getsalary()); //Create the input parameters to pass to the web service //operation ArrayList parametervalue = new ArrayList(); parametervalue.add(gvt); ArrayList parametertypes = new ArrayList(); parametertypes.add(object.class); 13

//WS is based on EJB and thus we do have a merge operation for //existing objects and a persist operation for new objects. We //use the "newemployee" flag to distinguish the two use cases if (newemployee) { AdfmfJavaUtilities.invokeDataControlMethod("HrWSDC", null, "persistemployees", parameternames, parametervalue,parametertypes); //add new object t local cache employeelistcache.put(employee.getemployeeid(), employee); //notify update this.setemployeelistcache(employeelistcache); //notify container about the create else { AdfmfJavaUtilities.invokeDataControlMethod("HrWSDC", null, "mergeemployees", parameternames, parametervalue,parametertypes); // replace current entry in local cache employeelistcache.put(employee.getemployeeid(), employee); //notify update this.setemployeelistcache(employeelistcache); catch (AdfInvocationException e) { logapplicationmessage(level.severe, "Cannot update data accessing Web Service \n", ""+ e.getmessage()); Sample Download There is a lot more to say about this sample and therefore you want to have a look at its functionality and implementation after downloading the sample zip file. The Oracle JDeveloper 11.1.2.3 sources can be downloaded as sample "m05" from the ADF Code Corner website: http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html Android ADF Mobile allows mobile on-device applications to be developed for Apple ios and the Android platform (plus what will come in the future). From a development perspective this means that a single code line does it. So choosing between the two mobile platforms I decided for Android as the platform that I use for ADF Code Corner mobile sample development and testing. The development platform however should not matter as ADF Mobile is doing the cross-platform compilation trick for you. 14

However, from a perspective of what has been tested and where have samples been tested on, the answer is Android 2.3 and Android 4.0 for mobile phone and tablet. RELATED DOCOMENTATION Class GenericTypeBeanSerializationHelper http://docs.oracle.com/cd/e38668_01/apirefs.111230/e27204/oracle/adfmf/framework/api/gen erictypebeanserializationhelper.html ADF Mobile Set-up Tutorial http://docs.oracle.com/cd/e18941_01/tutorials/mobiletutorial/jdtut_11r2_54_1.html ADF Mobile Tutorial http://docs.oracle.com/cd/e18941_01/tutorials/buildingmobileapps/adfmobiletutorial_1.html 15