Oracle MAF: Push page button using Javascript

person Bijeshfolder_openMAF, Oraclelocal_offer, access_time August 11, 2015

A common requirement on MAF is to simulate a page button push using Javascript. To achieve this, what you need is a Javascript function that registers two events on the button – “touchstart” and “touchend”.

(function() {
      pressAMXButton = function()
          var eventTarget = document.getElementById(arguments[0]); //argument is the button id
          var touchStartEvt = new Event("touchstart");
          var touchEndEvt = new Event("touchend");

An use-case for this function may be to simulate clicking a search button when the user presses enter on the search key field. The typical way to do this would be to register a function against the keypress event on the window. The registered function in turn will invoke the pressAMXButton with the correct button id. For e.g.

            $(window).keypress(function (e) {  
                if (e.keyCode == 13) {                    

Theres is a gotcha with this though. If you have multiple pages within the same MAF feature – say within a single taskflow – and the user navigates between these pages, then it may be required that you unregister any previous keypress bindings before adding the new one. If you don’t then, you may encounter the issue where the keypress function that was registered on the very first page continues to be active on other pages also. The effect of this is that the Javascript may attempt to press a button that doesn’t exist on the new page.
Use this bit of Javascript prior to registering the new keypress function. This snippet unbinds all keypress functions registered on the window.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>