Tuesday, November 30, 2010

ADF Faces Rich Client Development

In this blogpost I will try to give you a jumpstart in javascript development. For ADF Faces RC development you need to have JDeveloper 11g together with Mozilla FireFox & the FireBug plugin.
This blogpost is inspired by the great work of Frank Nimphius ( Lot's of demos and a very good chapter in his book ) and a very nice blogpost of Chris how you can use hotkeys, to switch Tabs in UIShell.

Before you can start we need to add some context parameters to the web.xml
I set the to ERROR because the RC frameworks generates a lot of INFO messages, so you won't see your own log messages.
The parameter enables the Javascript Logger popup window, when the firebug console is enabled then this popup won't launch and the messages will be seen in the firebug console window.
The org.apache.myfaces.trinidad.DEBUG_JAVASCRIPT will allow to debug a javascript file in the firebug debug console.

The next step is to create a javascript file and put this in a new folder in the Web Content folder of your web application.

To load the javascript files in your ADF Web Application you can use af:resource
<af:resource type="javascript" source="js/keys.js"/>
When you do this in the JSPX page then every page / region or fragment can call these javascript methods.
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="" version="2.1"
  < contentType="text/html;charset=UTF-8"/>
  <f:view beforePhase="#{viewScope.HandleKeys.registerKeyboardMapping}">
    <af:document id="document" title="Client Side">
      <af:resource type="javascript" source="js/keys.js"/>
      <af:resource type="javascript" source="js/utils.js"/>
      <af:serverListener type="keyboardToServerNotify"
      <af:form id="f1">
        <af:pageTemplate viewId="/oracle/ui/pattern/dynamicShell/dynamicTabShell.jspx"
                         value="#{bindings.pageTemplateBinding}" id="pt1">

To call a javascript method from your JSF page you can use af:clientListener where you need to provide the method name and how it is activated.
<af:clientListener method="numbersOnly" type="keyDown"/>

Here an example of a javascript method
function numbersOnly(evt){
     var _keyCode = evt.getKeyCode();
     var _filterField = evt.getCurrentTarget();
     var _oldValue = _filterField.getValue();
     AdfLogger.LOGGER.logMessage(AdfLogger.ERROR, "key: "+_keyCode);
     //check for characters
     if (_keyCode > 64 && _keyCode < 91){  
In this code the AdfLogger.LOGGER.logMessage will log a message in the firebug console or logging popup.

ADF 11g has a very large Javascript API which you can use in your own Web Application, to see the API, click here.

You can also pass on data to the javascript method. You can use the af:clientAttribute for this with as value a text or an EL expression.
<af:panelHeader text="Tab Order" id="ph4">
     <af:panelFormLayout id="pform" clientComponent="true">
      <af:inputText id="it3" label="Tab 1">
        <af:clientAttribute name="tabindex" value="1"/>
        <af:clientListener method="setTabIndex('1','4')" type="keyPress"/>
      <af:inputText id="it4" label="Tab 3">
        <af:clientAttribute name="tabindex" value="3"/>
        <af:clientListener method="setTabIndex('1','4')" type="keyPress"/>
      <af:inputText id="it5" label="Tab 4">
        <af:clientAttribute name="tabindex" value="4"/>
        <af:clientListener method="setTabIndex('1','4')" type="keyPress"/>
      <af:inputText id="it6" label="Tab 2">
        <af:clientAttribute name="tabindex" value="2"/>
        <af:clientListener method="setTabIndex('1','4')" type="keyPress"/>
To get the clientAttribute value in javscript you can use this in javascript , component.getProperty("tabindex") Or you can do a Javascript callback
function setTabIndex( min, max) {
     return function (evt) {
       var minTabIndex = min;
       var maxTabIndex = max;
       var keyCodePressed = evt.getKeyCode();
       var keyModifiers = evt.getKeyModifiers();
       var component = evt.getSource();
       var panelForm = component.getParent();

       if ( keyCodePressed == AdfKeyStroke.TAB_KEY ) {
         var tabIndex = parseInt(component.getProperty("tabindex"));

Next question will be, how can you invoke a method in a managed bean (serverside) from the clientside. For this we can use af:serverListener, but you can not invoke this managed bean method directly. You need to fire a client ADF Event from the clientListener method. like this AdfCustomEvent.queue( source, "clickOnRow", {}, false);
<af:table value="#{bindings.allDepartments.collectionModel}" var="row"
               emptyText="#{bindings.allDepartments.viewable ? 'No data to display.' : 'Access Denied.'}"
               rowBandingInterval="0" rowSelection="single" id="departmentTable"
      <af:clientListener method="clickRow" type="click"/>
      <af:serverListener type="clickOnRow" method="#{Client.goCurrentRow}"/>
      <af:column sortProperty="departmentId" sortable="false"
       <af:outputText value="#{row.departmentId}" id="ot3">
        <af:clientAttribute name="departmentId" value="#{row.departmentId}"/>
        <af:clientListener method="showPopup('::deptPopup','dialog1','departmentId')"
      <af:column sortProperty="departmentName" sortable="false"
                 id="c2" width="200">
       <af:outputText value="#{row.departmentName}" id="ot1"/>
Here is the javascript for the ADF Client Event.
function clickRow(evt) {
     var source = evt.getSource();
     AdfLogger.LOGGER.logMessage(AdfLogger.ERROR, "clickOnRow");
     AdfCustomEvent.queue( source, "clickOnRow", {}, false); 
And the managed bean method.
public void goCurrentRow(ClientEvent clientEvent) {
       // Determine which row is currently selected in the RichTable
       RichTable deptTable = (RichTable)clientEvent.getComponent();
       Iterator keys = deptTable.getSelectedRowKeys().iterator();
       while (keys.hasNext()) {
           Key key = (Key)((List);

The only thing still to do is to debug the javascript methods. Start you Web application in FireFox and open the firebug application.  Click on the script Tab.

 Select the javascript file which you want to debug.

Set the breakpoint and debug through your application.

Here is my demo application with the following client examples ( thanks to Frank ).

  • Hotkeys for Tab switching
  • Tab Order
  • Clear validation messages
  • Type only numbers in a inputtext.
  • Click on a record and invoke a managed bean method
  • Click on a inputtext and display the value in a popup

Here you can download the demo workspace


  1. Hi Biemond. Nice article!

    I was wondering how can I click an ADF command button from inside a .js file included in an html inside an af:inlineFrame: all this to integrate Oracle Map with ADF: I want that my "click" on a javascript object propagates to an adf button.
    To be clearer, my page structure is:
    inlineFrame (this contains the map, an HTML with javascripts)


    is this possible? Can you suggest me something ?

  2. Hi,

    I think this is simple, just lookup you adf button id and call the click on this button.


  3. Hi Edwin,

    Regarding clicking a button programatically from java script. I am having the above code:
    var eventSource = actionEvent.getSource();
    var button = eventSource.findComponent("cmi2");
    where cmi2 is a menu button.

    on button I can't use click() function since it is not found on this object.
    How can I force in ADF a click on a button from javascript?

    Regards Corneliu

  4. Hi again,

    Finaly I succeded to call click button programaticaly from js.
    I used:
    var partialSubmit = true;
    AdfActionEvent.queue(button, partialSubmit);

    Regards Corneliu

  5. Interesting post - I Appreciate the points ! Does someone know where my business can locate a sample Wounded Warrior Handbook version to edit ?