Tuesday, March 19, 2013

Assigning Enter Key to a button on OAF Page


In lot of web pages if we press enter, then it submits the page. Similarly we can also submit the page on pressing Enter key in our Custom OAF pages. If there are more than one button then we can assign Enter key to one of the button. This way the user can submit the page by just pressing on Enter key. Below code gives you an idea on how to assign enter key to a button(page can contain any number of submit buttons). It's obvious that we can only assign Enter key to one button in a page. So when the user presses enter key, the page gets submitted and execute the respective code.

Note: When we implement Search bean in OAF, by default Enter key is assigned to Go button in the search bean. So when the user clicks on enter search gets executed automatically.

import java.util.Hashtable;
import oracle.apps.fnd.framework.webui.OABoundValueEnterOnKeyPress;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;

public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
    OAPageLayoutBean page = pageContext.getPageLayoutBean();
    Hashtable applyParams = new Hashtable();
    /*There is a button in the page with id 'Apply' and     we are assigning Enter key to this Apply button.*/     applyParams.put ("Apply", "VAL1");     page.setAttributeValue(           OAWebBeanConstants.ON_KEY_PRESS_ATTR,           new OABoundValueEnterOnKeyPress(pageContext,                 "DefaultFormName", // enclosing form name                 applyParams, // request parameters                 false, // client unvalidated                 false)); // server unvalidated } public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)   {     super.processFormRequest(pageContext, webBean);     /*When the user clicks on Enter key then the page     consider it like Apply button is pressed.*/     if (pageContext.getParameter("Apply") != null)     {        --Do your work here         } }

Please let me know if I miss any points. I am happy to add here if it's relevant.

No comments:

Post a Comment