1 Reply Latest reply on Mar 14, 2013 3:18 PM by Don Kleppinger

    How to skip validation using serverListener


      I am using Jdev

      My requirement was to called some action using the keyboard key.

      I tried with Access key first but its behaving differently in different browser.

      Crome: allowing action on access key press.
      IE : setting the focus on commandLink.

      Note : I have defined accessKey for RichCommandLink.

      Then i used the different approach which is as follows:

      1- Register the keyBoard handler to document. on beforePhase Event.
      2- Added the js file as follows :
      Javascript file:
      var keyRegistry = new Array();
      keyRegistry[0] = "alt 1";
      keyRegistry[1] = "alt 2";
      keyRegistry[2] = "alt 3";
      keyRegistry[3] = "alt 4";
      keyRegistry[4] = "alt 5";
      keyRegistry[5] = "alt 6";
      keyRegistry[6] = "alt 7";
      keyRegistry[7] = "alt 8";
      keyRegistry[8] = "alt 9";
      keyRegistry[9] = "alt 0";
      function registerKeyBoardHandler(serverListener, afdocument) {
        _serverListener = serverListener;
        var document = AdfPage.PAGE.findComponentByAbsoluteId(afdocument);
        _document = document;
        for (var i = keyRegistry.length - 1; i >= 0; i--) {
          var keyStroke = AdfKeyStroke.getKeyStrokeFromMarshalledString(keyRegistry); 
      AdfRichUIPeer.registerKeyStroke(document, keyStroke, callBack);

      function callBack(keyCode) {
      var activeComponentClientId = AdfPage.PAGE.getActiveComponentId();

      // Send the marshalled key code to the server listener for the developer
      // To handle the function key in a managed bean method
      var marshalledKeyCode = keyCode.toMarshalledString();

      _serverListener, {keycode:marshalledKeyCode,
          activeComponentClientId:activeComponentClientId}, true);

      // indicate to the client that the key was handled and that there
      // is no need to pass the event to the browser to handle it
      return true;
      *jspx page:*
      <f:view beforePhase="#{KeyboardHandler.registerKeyboardMapping}">
      <f:loadBundle basename="properties/Labels" var="labels"/>
      <af:document id="adfDocument">
      <af:resource type="javascript" source="/js/keyboard.js"/>
      <af:serverListener type="keyboardToServerNotify" method="#{KeyboardHandler.handleKeyboardEvent}" />
      *Java Code :*
      public class KeyboardHandler {
      public KeyboardHandler() {
      public void registerKeyboardMapping(PhaseEvent phaseEvent) {

      if (phaseEvent.getPhaseId() == PhaseId.RENDER_RESPONSE) {

      FacesContext facesContext = FacesContext.getCurrentInstance();
      ExtendedRenderKitService extRenderKitService =
      List childComponents = facesContext.getViewRoot().getChildren();
      //First child component in an ADF Faces page - and the only child - is af:document
      //Thus no need to parse the child components and check for their component family
      String id =

      StringBuffer script = new StringBuffer();
      script.append("window.registerKeyBoardHandler('keyboardToServerNotify','" +
      id + "')");
      extRenderKitService.addScript(facesContext, script.toString());
      public void handleKeyboardEvent(ClientEvent clientEvent) {

      String keyCode = (String)clientEvent.getParameters().get("keycode");
      System.out.println("KeyCode ::"+keyCode);
      //Here on basis of numeric key 0-9 i will decide different action
      This is working fine and launching the first action successfully.
      *Now problem is that when i invoked second action its asking me enter data for required fields.*
      If i was invoking serverlistener from button than I can control immediate property of command button. but here serverListener is getting called form document. How can I avoid validation here.
      Can anybody please me?
      Thanks a lot in advance.
      -Amit Sharma