Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label af:clientListener. Show all posts
Showing posts with label af:clientListener. Show all posts

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 22 September 2014

Invoke button action (ActionEvent) and value change listener using JavaScript- Oracle ADF

This is another post about using JavaScript in ADF Faces, So again nothing complicated just simple things but needed often
In this post i am covering two simple requirements , using Jdeveloper 11.1.2.4 (11g Release2)

1. How to call button action (ActionEvent) using JavaScript
2. How to call valueChangeListener of a component using JavaScript

 

Call button action using JavaScript-


So for this just drop a commandButton and an inputText on page and create a ActionListener in managed bean for button



Code in managed bean for ActionEvent-




    /**Action Listener for Button
     * @param actionEvent
     */
    public void buttonAction(ActionEvent actionEvent) {
        FacesMessage msg = new FacesMessage("Button Action called");
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, msg);
    }

Now requirement is to call this button action on double click event of mouse in inputText
To handle ActionEvent in JavaScript, framework provides a class AdfActionEvent , it has a method to queue ActionEvent from a component. So here i use same method to call ActionEvent

See JavaScript function-

function callButtonAction() {
                  //Method to get component using id (here button is top container)
                  var button = AdfPage.PAGE.findComponentByAbsoluteId('cb1');
                  //Method to queue ActionEvent from component
                  AdfActionEvent.queue(button, button.getPartialSubmit());
              }

and call it using af:clientListener under af:inputText-



Run page and check on double click of mouse in inputText-




Call ValueChangeListener using JavaScript-


This is also same as pervious one, created a valueChangeListener in managed bean for input text and requirement is to call this listener on mouse hover of button

Code in managed bean for ValueChangeListener-

    /**ValueChangeListener for inputText
     * @param valueChangeEvent
     */
    public void inputTextVCE(ValueChangeEvent valueChangeEvent) {
        FacesMessage msg = new FacesMessage("Value Change Lestener called");
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, msg);
    }

There is a class to handle valueChange event using JavaScript - AdfValueChangeEvent
So this class also has a queue method , the difference is this queue method takes 4 parameters and also requires a value change event on component
So first step is to change (set) value of field using JavaScript and then queue valueChangeEvent

See JavaScript function-


 function callValueChangeEvent(evt) {
                  //Method to get component using id (here inputText is top container)
                  var field = AdfPage.PAGE.findComponentByAbsoluteId('it1');
                  //Change(set) field's value
                  field.setValue('I am JavaScript text');
                  //Get New changed value
                  var newVal = field.getValue();
                  //Queue ValueChangeEvent (component,oldValue,newValue,autoSubmit)
                  AdfValueChangeEvent.queue(field, null, newVal, false);

              }

make sure that clientComponent and autoSubmit property of inputText set to true
call this javascript fucntion from button using af:clientListener


Run page and check it-
Thanks, Happy Learning


Saturday 8 March 2014

Launching browser print dialog using simple javascript function in ADF

Hello All ,
This posts talks about a requirement of printing a simple page (not much component as, form,tree,etc & not much data)
you can use a simple one liner javascript function to invoke browser's print dialog.

  • there is a page with Departments table on it, and a button to print this page

  • Called this simple javascript function on button click to open print dialog

  • window.print();
    

  • to execute javascript through managed bean use this method 



  •     /**Method to execute Javascript
         * @param javascriptCode
         */
        public static void runJavaScriptCode(String javascriptCode) {
            FacesContext facesCtx = FacesContext.getCurrentInstance();
            ExtendedRenderKitService service = Service.getRenderKitService(facesCtx, ExtendedRenderKitService.class);
            service.addScript(facesCtx, javascriptCode);
        }
    

  • click on print button- In Google Chrome

In Mozilla-




after printing, the page look like this
Sample ADF Application- Download
Cheers :-)

Tuesday 28 January 2014

Disabling keyboard input in af:inputDate, restrict user to use calendar only - Oracle ADF

hello all,
this tutorial is about a requirement of restricting user to enter date through calendar only in ADF application
this trick was posted by Frank Nimphius (ADF Code Corner)

  • Drop a af:inputDate component on page from component pallete



  • Now set its background color so that it looks like disabled field

  • Now to make it's input field disable, we have to write a small javascript function, copy this function and paste in your page source (XML)

  • <af:resource type="javascript">
              function enableCalendarOnly(evt) {
                  evt.cancel();
              }
            </af:resource>
    

  • Now drop a af:clientListener under af:inputDate component to invoke javascript



  • Now set properties in af:clientListener as Method & Type



  •  Now run your page and see that input field is disabled for date component , now value can be selected using calendar only

 Cheers - Happy Learning :-)

Saturday 1 June 2013

Using JQuery in Oracle ADF

JQuery is advance javascript library to support client side scripting of HTML, it is free and Opensource software licensed under MIT.
Jquery is designed to make it easier to create animations, enhance look feel of component, smooth navigation.
Read about Jquery- http://jquery.com/ , https://jquery.org/
here i am showing you, how to add Jquery in oracle ADF application.

  • First add Jquery library to your fusion web application, download library file Download
  • Add this file to javascript resources, see image
  • Now create a javascript(Jquery) file to change color of af:inputText, here is javascript code is given




  • function changeColor() {
        if ($("input[name=it1]").val() != null) {
           if (($("input[name=it1]").val().length > 0) && ($("input[name=it1]").val().length < 3)) {
                $("input[name=it1]").css("color", "magenta");
            }
          else if (($("input[name=it1]").val().length > 3) && ($("input[name=it1]").val().length < 6)) {
                $("input[name=it1]").css("color", "red");
            }
            else if (($("input[name=it1]").val().length >= 6) && ($("input[name=it1]").val().length < 9)) {
                $("input[name=it1]").css("color", "yellow");
            }
             else if (($("input[name=it1]").val().length >= 9) && ($("input[name=it1]").val().length < 12)) {
                $("input[name=it1]").css("color", "maroon");
            }
             else if (($("input[name=it1]").val().length >= 12) && ($("input[name=it1]").val().length < 15)) {
                $("input[name=it1]").css("color", "teal");
            }
             else if (($("input[name=it1]").val().length >= 15) && ($("input[name=it1]").val().length < 18)) {
                $("input[name=it1]").css("color", "blue");
            }
            else {
                $("input[name=it1]").css("color", "green");
            }
        }
    }
    

  • Now create a jspx page , and call this JS file as a resource in jspx page, and also add Jquery Lib to jspx page as Resource

  • Now add a input text in page, and call javascript resource using af:clientListener

  • See the code of jspx page-

  • <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
              xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
        <jsp:directive.page contentType="text/html;charset=UTF-8"/>
        <f:view>
            <af:document title="JqueryADF.jspx" id="d1">
             <af:resource type="javascript" source="/javascript/libs/jquery-1.4.4.js"/>
             <af:resource type="javascript" source="/resources/js/inputText.js"/>
                <af:form id="f1">
                <af:inputText label="Chck JQ" id="it1" contentStyle="font-weight:bold;">
                            <af:clientListener type="keyDown" method="changeColor"/>
                        </af:inputText>
                
                </af:form>
            </af:document>
        </f:view>
    </jsp:root>
    

  • Now Run this application and enter value in input text field and see how color is changing with length




  • You can use this , with your password field, for any kind of alert, to make 'Find and Enter' games
  • One more thing , it is difficult to use Jquery with pagefragments because in page fragments component id's are like :t1:cb1, r1:t1:it2. and jquery does not support ':' so you can easily use this with .jspx page
  • Sample ADF application -Download