Please disable your adblock and script blockers to view this page

Search this blog

Wednesday, 19 November 2014

Populate Dynamic table and form using af:dynamicComponent and dynamic viewObject - Oracle ADF

This post is about a common development requirement- Can we increase or decrease number of fields , type of fields (columns in case of table), data in fields at run time?

Suppose i have to show data of Departments and Employees table on page using only one af:table component. It means columns should be generated dynamically at run time depending on any defined condition
So for this requirement i am using dynamic viewObject in model layer and af:dynamicComponent in view layer
See previous post about creating dynamic viewObject-
Creating Dynamic View Object at Runtime programmatically - Oracle ADF

See step by step implementation-
  • Create Fusion Web Application and follow the link posted above to create dynamic viewObject, in short create a viewObject using dual and a method in AMImpl to create dynamic viewObject from sql query


  •     /**Method to create viewObject using SQL query
         * @param query
    
    
    
    
    
    
    
         */
        public void createNewViewObject(String query) {
            ViewObject dynVo = this.getdynamic1();
            dynVo.remove();
            this.createViewObjectFromQueryStmt("dynamic1", query);
            this.getdynamic1().executeQuery();
        }
    

  • Created a page and added an inputText to enter SQL query and a button to process that query and create dynamic viewObject at run time


  • See Managed Bean code to process query, value of inputText is passed using component binding

  •     private RichInputText sqlQueryBind;
    
        public DynamicTableBean() {
        }
    
        /*****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 create viewObject
         * @param actionEvent
         */
        public void createViewObjectAction(ActionEvent actionEvent) {
            if (sqlQueryBind.getValue() != null) {
                OperationBinding ob = executeOperation("createNewViewObject");
                ob.getParamsMap().put("query", sqlQueryBind.getValue().toString());
                ob.execute();
            }
        }
    
        public void setSqlQueryBind(RichInputText sqlQueryBind) {
            this.sqlQueryBind = sqlQueryBind;
        }
    
        public RichInputText getSqlQueryBind() {
            return sqlQueryBind;
        }
    

  • Now dropped this dual viewObject on page as dynamic form and dynamic table from Data Control (this snap is about creating form)



  • Next is to change pageDef entry for this dynamic component , open pageDef and goto treeBinding. there is an entry for nodeDefinition, there will be separate treeBinding for form and table both (you should change both)

  •  <tree IterBinding="dynamic1Iterator" id="dynamic1">
                <nodeDefinition DefName="dynamictableapp.model.view.dynamicVO" Name="dynamic10"/>
            </tree>
    

    Change this entry like this-

     <tree IterBinding="dynamic1Iterator" id="dynamic1">
                <nodeDefinition Name="dynamic10"/>
            </tree>
    

  • Now run this application and enter SQL query in box and press process button


 Thanks, Happy Learning :)
Download -Sample ADF Application

Friday, 14 November 2014

ADF Faces dvt:thematicMap to mark location using latitude and longitude

Hello all,
this post is about simple use of dvt:thematicMap component , this map is used for displaying some information of a particular geographic location such as population ,any trends or patterns
Map is called thematic because it doesn't include geographic details of location as rivers, ocean etc.
If you want to use geographic features then use <dvt:map>

Thematic map includes different basemap as world map and all continents map
for details see oracle docs - <dvt:thematicmap>
In this post i am just spotting locations using their latitude and longitude co-ordinates

  • So first step is create a fusion web application and drop a thematic map (world map) on page



  • then i have created a bean class to populate data in thematic map , this bean class contains properties (varaibles) for thematic map like Country Name,latitude and longitude



  • public class LocationDetail {
        private String location; // Name of Location
        private String countryNm; // Name of Country
        private String textDisp; // Additional Information to display
        private float lattitude; // Latitude of location
        private float longitude; // Longitude of Location
    
        public LocationDetail() {
            super();
        }
    
        public void setLocation(String location) {
            this.location = location;
        }
    
        public String getLocation() {
            return location;
        }
    
        public void setCountryNm(String countryNm) {
            this.countryNm = countryNm;
        }
    
        public String getCountryNm() {
            return countryNm;
        }
    
        public void setTextDisp(String textDisp) {
            this.textDisp = textDisp;
        }
    
        public String getTextDisp() {
            return textDisp;
        }
    
        public void setLattitude(float lattitude) {
            this.lattitude = lattitude;
        }
    
        public float getLattitude() {
            return lattitude;
        }
    
        public void setLongitude(float longitude) {
            this.longitude = longitude;
        }
    
        public float getLongitude() {
            return longitude;
        }
    }
    

  • created a managed bean and a List data structure to add location detail and added this List reference to thematic map component

  • <dvt:thematicMap basemap="world" id="tm1" summary="World Map" styleClass="AFStretchWidth"
                                         partialTriggers="::b1" inlineStyle="background-color:#e9ffdc;">
                            <dvt:areaLayer layer="continents" id="al2">
                                <dvt:pointDataLayer id="dl1" value="#{viewScope.MapBean.mapDetail}" var="row">
                                    <dvt:pointLocation id="pl1" type="pointXY" pointY="#{row.lattitude}"
                                                       pointX="#{row.longitude}">
                                        <dvt:marker id="m1" shortDesc="#{row.textDisp}"
                                                    fillColor="#ff0000" borderWidth="1.0" scaleX="2.0" scaleY="2.0"
                                                    labelDisplay="on" labelPosition="bottom" shape="triangleDown"
                                                    value="#{row.location}" labelStyle="color:maroon;font-size:10px;"/>
                                    </dvt:pointLocation>
                                </dvt:pointDataLayer>
                            </dvt:areaLayer>
                        </dvt:thematicMap>
    

  • then i have added a form on page to add new location by user, this form has 5 fields (Country Name, Location, Latitude, Longitude and Description) and a button to add this information to list

  • <af:panelBox text="Add New Location" id="pb1" showDisclosure="false">
                            <f:facet name="toolbar"/>
                            <af:panelFormLayout id="pfl1" rows="1" maxColumns="2">
                                <f:facet name="footer">
                                    <af:button text="Add Location" id="b1"
                                               actionListener="#{viewScope.MapBean.addLocationButton}"/>
                                </f:facet>
                                <af:inputText label="Country" id="it3"
                                              contentStyle="width:100px;font-weight:bold;color:navy;"
                                              binding="#{viewScope.MapBean.cntryNmBind}"/>
                                <af:inputText label="Location" id="it4"
                                              contentStyle="width:100px;font-weight:bold;color:navy;"
                                              binding="#{viewScope.MapBean.locationBind}"/>
                                <af:inputText label="Latitude" id="it1" contentStyle="width:100px;color:red;"
                                              binding="#{viewScope.MapBean.latitudeBind}"/>
                                <af:inputText label="Longitude" id="it2" contentStyle="width:100px;color:red;"
                                              binding="#{viewScope.MapBean.longitudeBind}"/>
                                <af:inputText label="Description" id="it5" contentStyle='width:200px;color:darkgreen;'
                                              binding="#{viewScope.MapBean.descriptionBind}"/>
                            </af:panelFormLayout>
                        </af:panelBox>
    


  • now see the managed bean code to add this information to list and to populate default locations

  • public class MapBean {
        //List to contain Location Detail
        private List<LocationDetail> mapDetail = new ArrayList<LocationDetail>();
        // Bindings of page component to access value
        private RichInputText cntryNmBind;
        private RichInputText latitudeBind;
        private RichInputText longitudeBind;
        private RichInputText locationBind;
        private RichInputText descriptionBind;
    
        public MapBean() {
            // Add Default location to map
            LocationDetail location = new LocationDetail();
            location.setCountryNm("India");
            location.setLocation("Mumbai");
            location.setTextDisp("Economic Capital of India");
            location.setLongitude((float) 72.8258);
            location.setLattitude((float) 18.9750);
            mapDetail.add(location);
    
            location = new LocationDetail();
            location.setCountryNm("India");
            location.setLocation("Kanpur");
            location.setTextDisp("Industrial City in North India");
    
            location.setLongitude((float) 80.20);
            location.setLattitude((float) 26.28);
            mapDetail.add(location);
    
            System.out.println("List is-" + mapDetail);
        }
    
        public void setMapDetail(List mapDetail) {
            this.mapDetail = mapDetail;
        }
    
        public List getMapDetail() {
            return mapDetail;
        }
    
    
        /**Method to add new Location
         * @param actionEvent
         */
        public void addLocationButton(ActionEvent actionEvent) {
            if (cntryNmBind.getValue() != null && latitudeBind.getValue() != null && longitudeBind.getValue() != null &&
                locationBind.getValue() != null && descriptionBind.getValue() != null) {
    
                LocationDetail location = new LocationDetail();
                location = new LocationDetail();
                location.setCountryNm(cntryNmBind.getValue().toString());
                location.setLocation(locationBind.getValue().toString());
                location.setTextDisp(descriptionBind.getValue().toString());
    
                location.setLongitude(Float.parseFloat((String) longitudeBind.getValue()));
                location.setLattitude(Float.parseFloat((String) latitudeBind.getValue()));
                mapDetail.add(location);
            }
        }
    
        public void setCntryNmBind(RichInputText cntryNmBind) {
            this.cntryNmBind = cntryNmBind;
        }
    
        public RichInputText getCntryNmBind() {
            return cntryNmBind;
        }
    
        public void setLatitudeBind(RichInputText latitudeBind) {
            this.latitudeBind = latitudeBind;
        }
    
        public RichInputText getLatitudeBind() {
            return latitudeBind;
        }
    
        public void setLongitudeBind(RichInputText longitudeBind) {
            this.longitudeBind = longitudeBind;
        }
    
        public RichInputText getLongitudeBind() {
            return longitudeBind;
        }
    
        public void setLocationBind(RichInputText locationBind) {
            this.locationBind = locationBind;
        }
    
        public RichInputText getLocationBind() {
            return locationBind;
        }
    
        public void setDescriptionBind(RichInputText descriptionBind) {
            this.descriptionBind = descriptionBind;
        }
    
        public RichInputText getDescriptionBind() {
            return descriptionBind;
        }
    

  • you can see in thematicMap map source - how bean variables are used to point latitude, longitude etc
  • Run this application, you will see default location are marked at first time



  • now add any other location using 'Add New Location' form 


  • See this video how locations are added to thematic map using their latitude and longitude

and finally after adding all location , map looks like this

 Sample ADF Application
Thanks , Happy Learning :)

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 - http://www.smshorizon.in/ 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

http://smshorizon.co.in/api/sendsms.php?user=******&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 = "http://smshorizon.co.in/api/sendsms.php?";

            //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();
                myURLConnection.connect();
                reader = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
                //reading response
                String response;
                while ((response = reader.readLine()) != null) {
                    //print response
                    System.out.println(response);
                }
                System.out.println(response);
                //finally close connection
                reader.close();


            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    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

http://smshorizon.co.in/api/status.php?user=*****&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 java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

import javax.faces.event.ActionEvent;

import oracle.adf.view.rich.component.rich.input.RichInputText;

Thanks :) Happy Learning