Showing posts with label MAF. Show all posts
Showing posts with label MAF. Show all posts

August 26, 2018

How to run background service in Oracle MAF

In mobile apps, we often need some services to run in the background to do tasks like fetching or updating data from a server, sync local data with a server, invoking APIs etc.
In this post, we will see how to run a task in the background of a mobile app developed using Oracle MAF.

There is a default utility available in Oracle MAF to run java code in background threads which is MafExecutorService. It has a method execute() to run java runnable on a background thread in the context of the calling thread's MAF feature context. The syntax of the method is like

MafExecutorService.execute(new Runnable()
{
public void run()
{
         //Invoke your methods here     
}
});

If you update any data change events in the background, invoke below method to make it effective.

AdfmfJavaUtilities.flushDataChangeEvent();

April 13, 2018

Connecting Oracle Mobile Application Framework (MAF) with Oracle Intelligent Bots

[Oracle Intelligent Bot 18.1.1]

In this post, we will see how to create a client in Oracle Mobile Application Framework (MAF) to connect with chatbot developed in Oracle Intelligent Bot. In this example, I am using bot version 18.1.1 and sample server in the bot instance.

To achieve this, we need to 
  • Create a webhook channel in Bot
  • Create a channel in web socket server
  • Create a client in MAF
Create a webhook channel in Bot

  • Go to settings in bot service
  • Select Channels tab
  • Click on “+ Channel” button, a window will be opened to create a channel
    • Fill name and description fields
    • Select Channel Type as “webhook”
    • Platform version as “1.1 (Conversation model)”
    • Fill Outgoing webhook URI as below (Below is a sample url if you are using sample server and channel id you can copy from webhook url. If you are using other server, please fill this accordingly)
      • https://bots-samples-nodejs:8889/ext/apps/chat/bots/<channel id>/messages
    • Enable the channel and Click on create












Create a channel in web socket server
  • Open admin console of the sample server : http://<host>:8888/ext/apps/chat/admin/
  • Select Channels tab
  • Click on “New Channel” button
    • Fill name and description
    • Copy server key and webhook URL from the bot created above and fill here
    • Click on Save






Create the client in MAF

Please follow below steps to integrate MAF with the web chat client widget.
  • Go to dev-resources of the bot instance and download the web client source code
  • Create a MAF application
  • Go to folder structure and navigate to public_html folder under ViewController folder of the app
  • Copy web client source code folder inside the public_html folder
  • Go to jdeveloper, open maf-feature.xml
  • Click on + icon and create a new feature
  • Under content, select type as “Local HTML”
  • In the copied chatclient folder, there is an index.html page. Select this page for URL under the feature content
  • Open settings.js file inside the chatclient folder
  • Update the Uri and channel id with your bot details
  • User id is hardcoded here to “Anand”, but you can pass username at runtime if required
  • Now, run the app, a chat window will appear in the app




March 16, 2018

Oracle MAF: How to get the current row object of an binding iterator programmatically

[Oracle MAF 2.3.1]

Below is a code snippet helps to get the current object of a binding iterator from Java program in Oracle Mobile Application Framework (MAF).

AmxIteratorBinding ib = (AmxIteratorBinding)
           AdfmfJavaUtilities.evaluateELExpression("#{bindings.listIncidetnsIterator}");
oracle.adfmf.dc.bean.ConcreteJavaBeanObject obj=
           (oracle.adfmf.dc.bean.ConcreteJavaBeanObject)ib.getCurrentRow();   
IncidentVORow row=(IncidentVORow) obj.getInstance();


-- Where

  • #{bindings.listIncidetnsIterator} is binding iterator expression for a list of Incident objects
  • IncidentVORow is a bean class of incident object
  • "row" contains the current row of the iterator binding

February 14, 2018

Oracle MAF 2.5.0 Released


Oracle Mobile Application Framework (MAF) released a new version 2.5.0.
This is a major release containing a number of platform upgrades and enhancements, including the following:
  • A NEW release of JDeveloper 12.2.1.3.0 is required
  • The embedded Cordova platform engines have been updated
  • Support iOS 11, iPhone X and Xcode 9
  • Support Android 8, and the Google Pixel C phone
  • For faster performance, MAF applications now evaluate EL expressions in the Java VM layer!
  • The inputDate component has been changed such that tapping the up arrow increases the value and the down arrow decreases the value. To keep the older behavior, there is a new attribute (legacyMode) whose value can be set to true.
  • Now support JDeveloper constructs to deploy MAF applications to the Universal Windows Platform, which means that you can deploy your application from the command line
Please refer to the What's New section of the developer guide for detailed information about the changes and how they may affect you.

For additional release information, such as release notes and certification matrix, please refer to the MAF documentation on OTN

January 26, 2018

Resolving or Invoking a Method Expression from a Managed Bean in Oracle MAF

[MAF 2.3.1]

I developed a mobile app using Oracle Mobile Application Framework (MAF) in which I had a requirement to invoke a method from a managed bean method. Below is the code snippet worked for me to do this.


public static Object resloveMethodExpression(String expression,
                                             Class returnType,
                                             Class[] argTypes,
                                             Object[] argValues) {
  MethodExpression methodExpression = AdfmfJavaUtilities.getMethodExpression(expression,
                                                                             returnType,
                                                                             argTypes);
  return methodExpression.invoke(AdfmfJavaUtilities.getAdfELContext(), argValues);
}


Where,
  •  expression:  the managed bean method EL expression
  • returnType:  Class name of the return value of the method, can be null if it is void
  • argTypes: Class names of the input parameters need to be passed to the method if any. It would be null if there are no parameters
  • argValues: Input parameter values to be passed to the method if any. It would be null if there are no parameters


June 5, 2017

Oracle MAF 2.4.0 released

The new release of version 2.4.0 of Oracle Mobile Application Framework (MAF) is announced recently. This is a major release containing significant enhancements, such as improved Android builds, shared data controls, shared libraries and iOS 3D touch support, to name a few.

Please refer to the What's New section of the developer guide for detailed information about the changes and how they may affect you.

Visit the MAF Blog for more details.


April 27, 2017

Error: oracle.maf.impl.cd.datasynch not found

[maf 2.3.1]

I am developing a mobile application with MCS offline sync feature using Oracle MAF. I have used AMPA for the implementation. After deploying the application, on click of "Pending Sync Actions", I got the below error.

Feature not found with id "oracle.maf.impl.cd.datasynch"



This is because the library might be deleted or corrupted in the application. To avoid this error, we need to re-add the library. Below is the procedure to do so.
  • Go to application properties -> Libraries and Classpath
  • If you see libraries "DataSynchFeature.jar" and "WebServiceCallsFeature.jar", remove them
  • Click on "Add JAR/Directory..." and go to the path <jdev_home>/jdeveloper/jdev/extensions/oracle.maf/FARs/CDM
  • Selet both the jar files "DataSynchFeature.jar" and "WebServiceCallsFeature.jar" and add them
  • Click Ok
Now clean and re-deploy the application. It worked for me.




November 1, 2016

How to open device camera or picture gallery from Oracle MAF app

MAF provides a device feature method getPicture() to open the device camera or picture gallery. You can create binding to it if you want to open camera on the app. But if you want to handle this from java code in MAF, then check the below post.

Below is the code should be used to access the camera from the java code in MAF.

DeviceManager dm = DeviceManagerFactory.getDeviceManager();
String result=   dm.getPicture(75, dm.CAMERA_DESTINATIONTYPE_DATA_URL, dm.CAMERA_SOURCETYPE_CAMERA, false, dm.CAMERA_ENCODINGTYPE_PNG, 300, 250);

This method returns a string value with either base46 encoding string or the file path of the image based on the given destination type.

Syntax of the method is:
getPicture(int quality, int destinationType, int sourceType, boolean allowEdit, int encodingType, int targetWidth, int targetHeight) 

Where

quality: Quality of saved image
destinationType: Type of the return value whether it is base64 encoding string or file path. For base64 use 0=DESTINATIONTYPE_DATA_URL or for file path use 1 = DESTINATIONTYPE_FILE_URI
sourceType: What is the source of the picture whether it is device camera or photo gallery. For gallery use 0=CAMERA_SOURCETYPE_PHOTOLIBRARY or for camera use 1=CAMERA_SOURCETYPE_CAMERA
allowEdit: Allow simple editing of image before selection
encodingType: the encoding of the returned image file. Select 0 = CAMERA_ENCODINGTYPE_JPEG for JPEG image or 1 = CAMERA_ENCODINGTYPE_PNG for PNG image
targetWidth: Width in pixels to scale image
targetHeight: Height in pixels to scale image

Note: you can not test camera in iOS Simulator or Android Emulator. The camera can be tested only on the device, but you can test the gallery in the Simulator or Emulator. To check if the running device is Simulator or Emulator, you have to give a condition like,

if (dm.getName().indexOf("Simulator") != -1)  // For iOS Simulator
if (dm.getName().indexOf("sdk") != -1)            //For Android Emulator

May 13, 2016

Cordova Plugin is not added to Oracle MAF

Issue:
I faced an issue where I could not able to add few cordova plugins to Oracle MAF application. I could able to select the plugin but after selected, it is not added to MAF and not showing any error also.

Solution:
Check the value of the attribute xmlns of the tag plugin in the plugin.xml file under the corddova plugin folder. Generally it is

xmlns="http://cordova.apache.org/ns/plugins/1.0"

Change the value to as below
xmlns="http://apache.org/cordova/ns/plugins/1.0"

Now re-try to add the plugin to MAF.

February 29, 2016

Adding a custom css/skin file to a Oracle MAF application

When we want to apply our own css to a Oracle MAF application, we need to configure a custom css file to it. Below is the procedure to know how to add a custom css/skin file to a MAF application.
  • Right click on ApplicationController project -> select CSS File -> enter css file name. Below is the default path of the file to be created. Here my css file name is myskin.css
            /ApplicationController/public_html/resources/css/mycss.css

  • Open maf-config.xml which is under Application Resources and check the skin family and version
         Ex
             <skin-family>mobileAlta</skin-family>
             <skin-version>v1.4</skin-version>

  • open maf-skins.xml which is under the project "ApplicationController" and create an xml entry like below
        <?xml version="1.0" encoding="UTF-8" ?>
         <adfmf-skins xmlns="http://xmlns.oracle.com/adf/mf/skin">
         <skin-addition id="s1">
         <skin-id>mobileAlta-v1.4</skin-id>
         <style-sheet-name>resources/css/myskin.css</style-sheet-name>
         </skin-addition>
         </adfmf-skins>

Where <skin-id> is the combination of skin-family and skin-version of maf-config.xml file seperated by "-" and enter the css file path for <style-sheet-name>.

February 3, 2016

How to integrate or configure InAppBrowser Cordova plugin in Oracle MAF

I have created a video to show how to integrate a Cordova plugin in Oracle MAF to show InAppBrowser in a mobile app. Click here to watch the video. This video also shows the procedure to integrate any other Cordova plugin with the Oracle MAF.

The MAF version 2.1 with JDeveloper 12c is used in this example.



Below are the steps to integrate the InAppbrowser Cordova plugin in Oracle MAF.
  1. Download the inappbrowser cordova plugin from https://cordova.apache.org to your machine
  2. Create a MAF application in JDeveloper
  3. Unzip the downloaded inappborwser plugin in your machine
  4. Copy and paste the plugin folder under the ViewController project folder in the MAF application
  5. Register or Configure the plugin in MAF application's maf-application.xml
  6. White list the domain you want to open in the app browser
  7. Create a java class and write a method to invoke inappbrowser api
  8. Create a button in amx page to bind the method
  9. Select the simulator and run the app
  10. Inappbrowser is ready. On click of the link in the app, a browser will be opened in the app with the given url. You can also choose to display extra buttons and navigation on this browser by changing the parameters passed in the java script api.

December 23, 2015

Using Rating Gauge as Status meter in Oracle MAF

I got a scenario in one of my MAF apps where I need to show the percentage of user profile completed in a circular graphical view. So, I have used rating gauge component in MAF to show this. I felt this would be useful to you also, so I have made a video to explain the procedure.

Click here to watch how to use rating gauge as status/progress meter in MAF.

November 18, 2015

java.sql.SQLException: stale connection

If you are getting the exception "java.sql.SQLException: stale connection" then you should check whether the Connection object is closed anywhere in the app and you are trying to access the same object. In this case, the object is closed and no longer available, so you can not do any execution on that object. 

Solution is to create a fresh connection object. 

If the error received in MAF apps, then remove the close statements as you don't need to close the connection in the mobile.

June 27, 2015

InAppBrowser in Oracle MAF using Cordova plug-in

This post is to show how to implement In-app browser in MAF using Cordova plugin.

If you have a url in the app, on click of the url, the URL will be open in a browser but if you want to come back to the app, you have to open your app tray and select the app. If you implement in-app browser, the url will be opened in a custom browser in the app itself, and you can see a button like "Done" on the browser. On click of that, you can return to the app.

Below is the procedure to develop the in-app browser using Cordova plugin.
  • Download the zip file of the project from Github and unzip it
  • Create a folder with the name plugins in ViewController project in the app
  • Copy file plugin.xml and folders www, src from the above Github project to the plugins folder
  • Open maf-application.xml file and select Plugins 
  • Under "Additional Plugins", add the plug in. See below screen for your reference

  • Write the below code in a java method and assign that method as an action or action listener to an action component in your page
          String urlToPen = "http://myfusionlearnings.blogspot.com";
          AdfmfContainerUtilities.invokeContainerJavaScriptFunction(        
         AdfmfJavaUtilities.getFeatureId(),
       "function(){cordova.InAppBrowser.open('"+urlToPen+"','_blank',              
        'location=no,toolbarposition=top,clearcache=yes');}", new Object[] {});

October 15, 2014

ERROR: Plugin 'Camera' not found, or is not a CDVPlugin. Check your plugin mapping in Cordova.plist

I am developing a MAF application in which I need to collect images from the user for which I provided a button. On click of the button, photo library supposed to be opened, so that the user can select the images. But on click of the button, I am getting the below error.

Error:
Plugin 'Camera' not found, or is not a CDVPlugin. Check your plugin mapping in Cordova.plist.

This is because the app is not granted access to required device capabilities.
To give the access, go to maf-application.xml and click on "Device Access", then grant access to required capabilities.

Below is the example where I granted for Camera and Files to avoid the above error.


September 10, 2014

Displaying alert message on AMX page from Managed Bean


Below java code is useful to display alert messages on AMX pages in MAF from managed bean.

AdfmfContainerUtilities.invokeContainerJavaScriptFunction("<feature-id>",
   "function(){navigator.notification.alert('<message>',  function(){}, '<alert-title>', '<button-text>');}",
   new Object[] { });

Ex:

AdfmfContainerUtilities.invokeContainerJavaScriptFunction("feature1",
"function(){navigator.notification.alert('Request has been submited.',  function(){}, 'Information', 'OK');}", new Object[] { });

Where
<feature-id> is the id of the feature on which you want to display the alert message
<message> is the message you want to display on the alert box
<alert-title> is the tile you want to display on the alert box
<button-text> is the text to be displayed on the button on alert box