Please disable your adblock and script blockers to view this page

Search this blog

Monday 8 December 2014

Show animated Image Caption using jQuery in ADF Faces

This is another post about using jQuery in ADF Faces, see previous posts on jQuery

Using JQuery in Oracle ADF 
Image zoom (power zoomer) effect using Jquery in ADF Faces

This post talks about - how to add mouse hover caption to images? Caption means a brief explanation of picture/image. Normally 'alt' attribute of HTML page is used as Image Caption
But in ADF Faces af:image doesn't has 'alt' property , there is a property called 'shortdesc' and this property is used as 'alt' attribute for image when jsf page is loaded at client browser
you can check this in html source of your page in browser (inspect element)




<af:image shortDesc="Black Horse running or flying" id="FirstImage"
                                  inlineStyle="height:300px;width:500px;"
                                  source="#{resource['images:Best-Wild-Animal-Photos-of-2012-307-black-horse-running.jpg']}"/>


JSF page is converted to html for client side presentation, see in HTML source 'shortdesc' is used as 'alt' property


jQuery is used for client side scripting of HTML so jQuery script makes use of this 'alt' attribute to show animated caption for image
There are lots of jQuery and JavaScript available for showing different types of captions , here i am using jQuery Capty - A Caption Plugin (Download jQuery script and respective css file from link)

Now follow steps to use this jQuery plugin with ADF Faces
  • Create Fusion Web Application and a page in viewController, added jQuery script and css in viewController project (Jdev 12.1.3)


  • Add jQuery library and script file reference to page, also add css file reference to page

  •  //jQuery library reference
                <af:resource type="javascript" source="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></af:resource>
                //jQuery file reference that will be used to show caption
                <af:resource type="javascript" source="js/jquery.capty.js"/>
                <af:resource type="javascript" source="js/jquery.capty.min.js"/>
                //CSS file to style Caption
                <af:resource type="css" source="css/jquery.capty.css"/>
    

  • Next step is to execute jQuery function on pageload to show caption

  • //Function to show default sliding caption
    
    $('#ImageId').capty();
    
    //Change default fucntion to change animation type , speed and height of caption
    
    $('#ImageId').capty({
    animation: 'fade',
    speed:     1000
    }) 
    

  • So here i am using both function for two different images (for first image animation type is slide (default) and for second it is fade), add clientListener to document tag and set it's type to 'load' (to execute jQuery function on pageload)

  •  <af:clientListener method="jQuery(document).ready(function($){ $('#FirstImage').capty(); $('#SecondImage').capty({animation: 'fade',   speed:     1000}) })" type="load"/>
    

  • Run application and see magic of jQuery

  • Image Caption (animation:slide)-

    Image Caption (animation:fade)-

  • you can change style (color,font etc) of caption box by modifying css sheet and size can be increased or decreased from jQuery function. for example i have changed color, font and size of caption box. see this

  • @CHARSET "UTF-8";
    
    div.capty-caption {
     background-color: red;
     color: #FFF;
     font: bold 11px cursive;
     padding-left: 10px;
     padding-top: 7px;
     text-shadow: 1px 1px 0 #222;
    }
    
    div.capty-caption a {
     color: #318DAD;
     font: bold 11px verdana;
     text-decoration: none;
     text-shadow: none;
    }
    

    jQuery function to increase size-

    jQuery(document).ready(function($){ $('#FirstImage').capty(); $('#SecondImage').capty({animation: 'fade',   speed:1000,height:50}) })
    

    See output-
Thanks, Happy Learning :)
Download Sample ADF Application

Tuesday 2 December 2014

Image zoom (power zoomer) effect using Jquery in ADF Faces

Jquery is most popular javascript library ,it is used to provide better ui design, animations and client side events
This is another post about using jquery in ADF Faces, see previous post
Using JQuery in Oracle ADF

In this post i am using a jquery script to zoom (enlarge) image on hover , you have seen this in many e-commerce websites as they provide power zoom feature to enlarge product image for better customer experience



I have taken this jquery script from Dynamic Drive, see the documentation
To implement this in ADF Application follow these steps
  • Create a Fusion Web Application and a page in viewController project (Jdev 12.1.3)


  • Downloaded jquery script file from above link -ddpowerzoomer.js, add this jquery file to viewController project


  • Now add jquery library reference in page in order to use jquery functions

  • <af:resource type="javascript" source="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></af:resource>
                <af:resource type="javascript" source="js/ddpowerzoomer.js"/>
    

  • Next step is to add an image to page , so added an af:image to page and set path of image to display


  • Now i have to execute jquery function that will add power zoom feature to this image (See jquery code that will be executed on pageload)

  • jQuery(document).ready(function($){
     $('#i1').addpowerzoom({
      defaultpower: 2,  powerrange: [2,5],  largeimage: null,  magnifiersize: [75,75]  }) 
    })
    

    here i1 is the id of image, default zoom power and magnifier size is configured here
  • So to execute this jquery function on pageload , added a clientListenr to pagelike this

  • <af:clientListener type="load"
                                   method="jQuery(document).ready(function($){   $('#i1').addpowerzoom({  defaultpower: 2,  powerrange: [2,5],  largeimage: null,  magnifiersize: [75,75]  }) })"/>
    

  • Now run this application and check it, magnifier is on deer :)


  • Now i am increasing size and power of magnifier - Power is 3 and size is 200x200
Thanks, Happy Learning :)
Download Sample ADF Application

Monday 24 November 2014

Populate af:table programmatically from managead bean using POJO

This post is about a common question
How can we populate an af:table programmatically ?

It means that data in af:table is not populated through model layer (Using ViewObject) using binding layer. lets say I have some values in our managed bean and have to show records in tabular format on page

So what we have to do -
  • First you should know the number and data type of columns in table, suppose i have to populate a table for person details (name, mobile number and salary). to get and set value of columns i have created a java bean class , it has 3 variable for 3 columns



  • // Java Class to set and get value for table column
    public class PersonBean {
    
        public PersonBean(String name, String moNo, Integer salary) {
            this.Name = name;
            this.mobNo = moNo;
            this.salary = salary;
        }
        private String Name;
        private String mobNo;
        private Integer salary;
    
        public void setName(String Name) {
            this.Name = Name;
        }
    
        public String getName() {
            return Name;
        }
    
        public void setMobNo(String mobNo) {
            this.mobNo = mobNo;
        }
    
        public String getMobNo() {
            return mobNo;
        }
    
        public void setSalary(Integer salary) {
            this.salary = salary;
        }
    
        public Integer getSalary() {
            return salary;
        }
    }
    

  • Next step is to create a managed bean for referencing af:table , this managed bean makes use of person java bean class to add data in same format for all table rows. A List data structure is used to pass all values in af:table. See code of managed bean 

  • //ArrayList to poplate data in af:table
        List<PersonBean> personList = new ArrayList();
    
        //To Populate default row in table (Code in Constructor)
    
        public ProgTableBean() {
            personList.add(new PersonBean("Ashish Awasthi", "xxxxxxxxxx", 50000));
        }
    
        public void setPersonList(List<PersonBean> personList) {
            this.personList = personList;
        }
    
        public List<PersonBean> getPersonList() {
            return personList;
        }
    

  • Now just drop an af:table on page and set it's properties like value, column header and text values in columns

  •  As i have to show only 3 columns so deleted extra ones

     Set properties -
     value- from where table collection is populated
     columns values- take the var reference of table and refer variable name in List (here 'row' is table var and second is variable name in person bean class)


     See the XML source of af:table-

    <af:table var="row" rowBandingInterval="1" id="t1" value="#{viewScope.ProgTableBean.personList}"
                              partialTriggers="::b1">
                        <af:column sortable="false" headerText="Name" id="c1" width="150">
                            <af:outputText value="#{row.name}" id="ot1"/>
                        </af:column>
                        <af:column sortable="false" headerText="Mobile Number" id="c2">
                            <af:outputText value="#{row.mobNo}" id="ot2"/>
                        </af:column>
                        <af:column sortable="false" headerText="Salary" id="c3" align="right">
                            <af:outputText value="#{row.salary}" id="ot3"/>
                        </af:column>
                    </af:table>
    

  • Now run this application and see there will be one row in table as code is added in constructor of managed to populate one row


  • I have added a form and button in page to add new records in table , see the form source code

  • <af:panelFormLayout id="pfl1">
                        <f:facet name="footer"/>
                        <af:inputText label="Name :" id="it1" binding="#{viewScope.ProgTableBean.nameBind}"/>
                        <af:inputText label="Mobile Number :" id="it2" binding="#{viewScope.ProgTableBean.mobNumBind}"/>
                        <af:inputText label="Salary :" id="it3" binding="#{viewScope.ProgTableBean.salaryBind}">
                            <af:convertNumber/>
                        </af:inputText>
                        <af:button text="Add Record" id="b1" actionListener="#{viewScope.ProgTableBean.addNewRcord}"/>
                    </af:panelFormLayout> 
     

    Code in managed bean for button action-

        /**Method to add new record in table
         * @param actionEvent
         */
        public void addNewRcord(ActionEvent actionEvent) {
            //Get all values using compoenet binding as mobNumBind
            if (mobNumBind.getValue() != null && nameBind.getValue() != null &&
                salaryBind.getValue() !=
                null) {
                // Add new Record in List
                personList.add(new PersonBean(nameBind.getValue().toString(), mobNumBind.getValue().toString(),
                                              Integer.parseInt(salaryBind.getValue().toString())));
            }
        }
    

  • now run and check application- 


 More posts on POJO Based table -

Get selected row (single/multiple) from POJO based table in ADF
Apply sorting to POJO based af:table programmatically , Using custom sort listener in ADF

Thanks , Happy Learning :)
Download-Sample ADF Application

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 :)