Tuesday, June 18, 2019

Stop closing popup when pressing escape(Esc)

Stop closing popup when pressing escape(Esc)
function handleDialog(event) {
        if(event.getOutcome() ==  AdfDialogEvent.OUTCOME_CANCEL) {
            event.cancel();
        }                      
    }


<af:clientListener method="handleDialog" type="dialog"/>

Wednesday, April 17, 2019

Set current date in af:inputDate on double click using javascript in ADF

set current date in af:inputDate component on double click of the mouse. For this, we need to use a simple javascript function.


Here we have an inputDate component on the page and added javascript function as a resource in the page. See page XML source

  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
  3. xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  4. <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  5. <f:view>
  6. <af:document title="SetCurrentDate.jspx" id="d1">
  7. <af:resource type="javascript">
  8. function setDate(evt) {
  9. var comp = evt.getSource()
  10. comp.setValue(new Date());
  11. }
  12. </af:resource>
  13. <af:form id="f1">
  14. <af:inputDate label="Label 1" id="id1">
  15. <af:clientListener method="setDate" type="dblClick"/>
  16. </af:inputDate>
  17. </af:form>
  18. </af:document>
  19. </f:view>
  20. </jsp:root>

Wednesday, January 9, 2019

Javascript in ADF

Using JavaScript in ADF Faces Rich Client Applications .pdf
Best Practice1:
-----------------
An oven alone doesn’t make a cook. Developers should ensure they understand the ADF Faces client architecture before using JavaScript in ADF Faces applications

Enhancing JavaServer Faces with ADF Faces By design, JavaServer Faces is a server-centric framework that executes server-side logic in response to form submits. In JSF, a client request is handled by up to six lifecycle phases that:
 Prepare the server-side memory tree
 Apply request parameter values
 Perform validation
 Update the business model
 Invoke component listeners and actions
 Prepare the response for render


ADF Faces JavaScript object scopes
---------------------------------------------
JavaScript doesn't know about abstract classes, or private, public and protected scopes. In ADF Faces however all of these are implemented through naming guidelines and coding patterns that application developers should not disregard. Abstract JavaScript classes in ADF Faces are implemented by some of its functions returning AdfAssert.failedInAbstractFunction when invoked. Abstract objects are indirectly used through their subclasses.

Object scopes in ADF Faces, not to be confused with JavaServer Faces memory scopes, are implemented by the following naming conventions:



Best Practice 2:
---------------------
Protected, package, or private methods and variables that DOM inspection tools like Firebug show for ADF Faces components and events should not be used in custom ADF Faces application development.


Adding JavaScript to on a page To use JavaScript on an ADF Faces view, application developers either add JavaScript code to the page source or reference it in an external library file. To ensure that the JavaScript sources are efficiently downloaded to the client,
ADF Faces provides the af:resource component tag, which must be added as a direct descendent of the af:document tag. Using JavaScript in ADF Faces Rich Client Applications 11 … 

/*
===


<af:document>
 <af:resource type="javascript" source="/customJsCode.js"/>
 …

</af:document>

<af:document>
 <af:resource type="javascript">
 function customJsFunction(){ … }
 </af:resource>
 …
</af:document>


*/


Finding ADF Faces components on the client The hierarchy of ADF Faces components on the client is the same as the component hierarchy on the server. The difference though is that not all ADF Faces components are rendered as client objects by default, but server-side generated HTML. For JavaScript to be able to access an ADF Faces component by its client component API, the first development task, therefore, is to ensure that a client component is generated. Creating client components Only components with behavior, like ADF Faces tables, have a default JavaScript object representation. For all other components, a client object is created when one of the following conditions is met: 

 A component has an af:clientListener tag added. The af:clientListener component allows JavaScript function to listen for ADF Faces component events, like select or disclosure events, and browser DOM events like focus, mouse hover, mouse click, or keyboard events.  The component has its clientComponent property set to true. 

handling focus (attributeids list)

/*
 * handling focus for navigation.
*/

function handlingFocus(attributeIds) {
                       return function settingFocus(evt) {
                           keyCode = evt.getKeyCode();
                           var arrayLength = attributeIds.length;
                           var temp1 = 0;
                           if (keyCode == AdfKeyStroke.TAB_KEY) {
                               while (arrayLength != 0) {
                                   var lastField = evt.getSource();
                                   var firstField = lastField.findComponent(attributeIds[temp1]);
                                   if (!firstField.getProperty("disabled")) {
                                       firstField.focus();
                                       evt.cancel();
                                       break;
                                   }
                                   else{
                                   //alert('Please pass the  valid Ids as argument');
                                   firstField = lastField.findComponent(attributeIds[arrayLength-1]);
                                   firstField.focus();
                                   evt.cancel();
                                   }
                                   temp1++;
                                   arrayLength--;
                               }
                           }
                       }
                   }