Follow by Email

Monday, 20 October 2014

Send SMS from Oracle ADF Application using Horizon SMS API

This post is about using SMS API to send SMS text to mobile from an Oracle ADF application
there are various SMS Gateway to send SMS using java and all java API's can be used with Oracle ADF

here i am using sms horizon (a bulk sms provider in india) see this SMS API integration with Java and Oracle ADF, follow the steps
First create an account with SMS Horizon - or User Login- SMS Horizon

you can purchase a trial package to test your code, they provide 200 sms for Rs 25 only. So After purchasing trial pack you will get and API Key and username

Login to your account and see your dashboard-

you will see your API key in this type of box-

Now first step is complete and second and last step is implement code in your managed bean
you can find Sample API files (code to use API in Java, C#, PHP etc) from there

So for this i have a created a Fusion Web Application and a page in it

created a managed bean and actionListener for this Send button
this url is used to send sms and it returns msgId of sent message******&apikey=*****8&mobile=xxyy&message=xxyy&senderid=xxyy&type=txt

See the ActionListener code -

    /**Method to send SMS using SMS Horizon API
     * @param actionEvent
    public void sendSMSAction(ActionEvent actionEvent) {
        // get mobile number value using component binding
        if (mobNoBind.getValue() != null) {
            // Replace with your username
            String user = "userId";

            // Replace with your API KEY (We have sent API KEY on activation email, also available on panel)
            String apikey = "your_api_key";

            // Replace with the destination mobile Number to which you want to send sms
            String mobile = mobNoBind.getValue().toString();

            // Replace if you have your own Sender ID, else donot change
            String senderid = "WEBSMS";

            // Replace with your Message content
            String message = "SMS API -Oracle ADF";

            // For Plain Text, use "txt" ; for Unicode symbols or regional Languages like hindi/tamil/kannada use "uni"
            String type = "txt";

            //Prepare Url
            URLConnection myURLConnection = null;
            URL myURL = null;
            BufferedReader reader = null;

            //encoding message
            String encoded_message = URLEncoder.encode(message);

            //Send SMS API
            String mainUrl = "";

            //Prepare parameter string
            StringBuilder sbPostData = new StringBuilder(mainUrl);
            sbPostData.append("user=" + user);
            sbPostData.append("&apikey=" + apikey);
            sbPostData.append("&message=" + encoded_message);
            sbPostData.append("&mobile=" + mobile);
            sbPostData.append("&senderid=" + senderid);
            sbPostData.append("&type=" + type);

            //final string
            mainUrl = sbPostData.toString();
            System.out.println("URL to Send SMS-" + mainUrl);
            try {
                //prepare connection
                myURL = new URL(mainUrl);
                myURLConnection = myURL.openConnection();
                reader = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
                //reading response
                String response;
                while ((response = reader.readLine()) != null) {
                    //print response
                //finally close connection

            } catch (IOException e) {

    public void setMobNoBind(RichInputText mobNoBind) {
        this.mobNoBind = mobNoBind;

    public RichInputText getMobNoBind() {
        return mobNoBind;

you can check status of each SMS in your account that it is delivered of not, other than this you can also check status of msg in your code also using this url*****&apikey=*********&msgid=xxyy

pass msgId returned from previous url and it will return you status of message as- PENDING , DELIVERED etc
see imports used in code-



import javax.faces.event.ActionEvent;


Thanks :) Happy Learning

Monday, 13 October 2014

Set values in af:selectManyChoice programmatically - Oracle ADF

This post is about a very common question
How to set selected values in af:selectManyChoice component ?
Sometimes we need to set some values in selectManyChoice component on some action

In this post i am using Departments table of HR Schema to create selectManyChoice (Multiple Selection)
Just drag and drop Departments viewObject as ADF Select Many Choice
see- Using Multiple Selection (selectManyListbox & selectManyCheckbox component) in ADF

(Jdev Version- 12.1.3)
dropped a button on page and on this button action ,  setting values in component
See this simple managed bean code -

import java.util.ArrayList;

import javax.faces.event.ActionEvent;


public class SetValueSmcBean {
    private RichSelectManyChoice selectMcBind;

    public SetValueSmcBean() {

    /**Methos to set selected values in SelectManyChoice
     * @param actionEvent
    public void setSelectedValuesAction(ActionEvent actionEvent) {
        ArrayList listVal = new ArrayList(20);
        //Add DepartmentId to list that you want to set as selected
        // Set this List as value using component binding
        //Refresh Component on page (partial target)

    public void setSelectMcBind(RichSelectManyChoice selectMcBind) {
        this.selectMcBind = selectMcBind;

    public RichSelectManyChoice getSelectMcBind() {
        return selectMcBind;

run application and check-

Downoad Sample Application
Thanks , Happy Learning :)

Tuesday, 7 October 2014

Better User Interface- Oracle Alta UI for Oracle ADF 12.1.3

Great news for all ADF developers ,
Oracle has launched a design system for better user experience - Oracle Alta UI (much more than skin)

see press release- Oracle Announces New User Interface Design System for a More Engaging Customer Experience
As per documentation -

Oracle Alta UI is a new user interface design system that enables developers to create modern, visually pleasing, consistent, and engaging interfaces that can be easily distributed across all delivery channels.
The Oracle Alta UI design system provides a set of guidelines and best practices. The system is based on years of user experience and usability implementations and analysis by leading UI and design specialists.
Oracle Alta UI-based applications feature a simplified component structure and more open space to keep the focus on data.

See details of Oracle Alta UI- Oracle Alta UI

I have created a simple master detail page using Departments and Employees table of HR Schema using Jdev 12.1.3

by default skyros skin is applied in fusion web application, you can see this in trinidad-config.xml file under WEB-INF node

to apply Oracle Alta UI just change skin-family to alta

Now compare both UI , you will see a big difference

Full page-
Default Skin-

Alta UI-

See difference in af:inputDate and it's calendar
Default Skin-

 Alta UI- (icon is inside date field)

inputListofValues box is very attractive now-
Default Skin-

 Oracle Alta UI-
and magnifier icon is inside field now-

try it yourself and see difference in other components also
refer- Designing & Developing Oracle ALTA UI Apps
Sample ADF Application- Download

Wednesday, 1 October 2014

Using Drag-Drop functionality in af:treeTable to move data between nodes -Oracle ADF

This is a very common question and development requirement - How to drag drop records inside treeTable to perform some kind of operation ?
This post is an answer,here i am using Departments and Employees table of HR Schema to create treeTable and Jdeveloper 12.1.3

First Step-
Create business components using Departments and Employees table of HR Schema and create association and viewLink using DepartmentId (here Departments is parent and Employee is child viewObject)

now drop Departments viewObject as treeTable on page from data-control
see- Tree Table Component in Oracle ADF(Hierarchical Representation)  (How to create treeTable in ADF)

So after creating simple treeTable, added  two columns other than nodeStamp to show DepartmentName and EmployeeName in a better way
see-Tree Table Component with declarative presentation in ADF

Finally it looks like this-

Now my requirement is - when drag an Employee to any Department node it should become child of that Department ,means attach Employee to Departments using drag-drop

So to drag Employee Name filed i added af:attributeDragSource under this field and to get corresponding EmployeeId added an af:clientAttribute component

This clientAttribute stores value of EmployeeId for each node and dragSource refers clientAttribute to identify node value
Now to handle dropEvent on DepatmentName node , dropped an af:dropTarget under this field and created a dropListener in managed bean that will handle desired operation on dropEvent

See complete af:treeTable xml source-

<af:treeTable value="#{bindings.Departments1.treeModel}" var="node"
                  selectionListener="#{bindings.Departments1.treeModel.makeCurrent}" rowSelection="single" id="tt1"
      <f:facet name="nodeStamp">
        <af:column id="c1" width="10">
          <af:outputText value="#{node}" id="ot1"/>
      <f:facet name="pathStamp">
        <af:outputText value="#{node}" id="ot2"/>
      <af:column id="c2" width="150">
        <af:outputText value="#{node.DepartmentName}" id="ot3"
          <af:dropTarget dropListener="#{pageFlowScope.DragDropBean.treeDropListener}">
            <af:dataFlavor flavorClass="java.lang.Object"/>
      <af:column id="c3">
        <af:outputText value="#{node.FirstName}" id="ot4" inlineStyle="font-weight:bold;color:darkgreen;">
          <af:clientAttribute name="DragEmployeeId" value="#{node.EmployeeId}"/>
          <af:attributeDragSource attribute="DragEmployeeId"/>

Now see the code of drop listener written in managed bean that gets EmployeeId value from dropEvent and DepartmentId from expression and calls a business logic to move employee under that Deaprtment

DropListener in ManagedBean to handle dropEvent-

    /**Method to move Employee Under Department
     * @param dropEvent
     * @return
    public DnDAction treeDropListener(DropEvent dropEvent) {

        Object empId = null;
        Integer dropVal = null;
        //Get Value from dragSource (EmployeeId of dragged node)
        DataFlavor<Object> df = DataFlavor.getDataFlavor(Object.class);
        empId = dropEvent.getTransferable().getData(df);
        if (empId != null) {
            System.out.println("Dropped value is -" + empId);
            try {
                dropVal = new Number(empId).intValue();
            } catch (SQLException e) {
            //Get DepartmentId where Employee is dropped (resolve Expression langusge)
            Object droppedUnderDept = resolvElDC("#{node.DepartmentId}");
            System.out.println("Dropped under-" + droppedUnderDept);
            //Method Call to mode Employee under Department
            OperationBinding ob = executeOperation("moveEmployeeToDepartment");
            ob.getParamsMap().put("deptId", Integer.parseInt(droppedUnderDept.toString()));
            ob.getParamsMap().put("empId", dropVal);
        /*Method to expand treeTable to show all nodes
         * see-
         * */
        //Refreshing treeTable after all operation, here treeTabBind is component binding of treeTable
        return DnDAction.NONE;


Helper methods to get BindingContainer and resolve expression-

    /*****Generic Method to call operation binding**/
    public BindingContainer getBindingsCont() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();

     * Generic Method to execute operation Binding
     * */
    public OperationBinding executeOperation(String operation) {
        OperationBinding createParam = getBindingsCont().getOperationBinding(operation);
        return createParam;


    /**Method to resolve Expression
     * @param data
     * @return
    public Object resolvElDC(String data) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class);
        return valueExp.getValue(elContext);

Now run your application and check -
Dragged Prabhakar from Purchase Department and dropped it on Finance-

Thanks, Happy learning :)
Download Sample App
See other post on Drag-Drop functionality- Adding Drag and Drop Functionality for collections in page fragments to create insert