Showing posts with label OAF. Show all posts
Showing posts with label OAF. Show all posts

Monday, July 1, 2013

DML Operations using Query based View Object

Recently there is a request in Oracle Forums/Spaces on how to save data into db tables using View Object(which is not based on Entity Object(EO)).

We already know that only EO based VOs can handle DML operations. If the query is complex, it may not be feasible to create EOs(and associations if any) and then base your VO on the EOs. In this case, it's better to create VO directly based on your complex query and then implement the DML operations by calling PL/SQL APIs from the VO. This way you can even do DML operations on more than one table. For this to achive Oracle has already provided a class oracle.apps.fnd.framework.server.OAPlsqlViewObjectImpl. By default, when we create any view object, it always extends oracle.apps.fnd.framework.server.OAViewObjectImpl which doesn't support any DML operations. In our case we need to create our View Object by extending OAPlsqlViewObjectImpl

Note: The class oracle.apps.fnd.framework.server.OAPlsqlViewObjectImpl has been deprecated. So implement this method only if you don't have alternative.

Below are the steps to achieve the desired result

  1. Create VO(MyVO) based on query as usual and generate the MyVOImpl and MyVORowImpl.
  2. Now go to MyVOImpl.java and change the extends to OAPlsqlViewObjectImpl. So your VOImpl should look like below
  3. public class MyVOVOImpl extends OAPlsqlViewObjectImpl
  4. Now go to MyVORowImpl.java and change the extends to OAPlsqlViewRowImpl
  5. public class MyVORowImpl extends OAPlsqlViewRowImpl
  6. MyVORowImpl has three methods to carry DML operations insertRow, updateRow, and deleteRow(inherited from OAPlsqlViewRowImpl).
  7. Override insertRow(byte)/insertRow and call respective PL/SQL procedure to insert row into the table. As this is RowImpl class you will get all values using their getter methods. Check javadoc for information about these two methods.
  8. Override updateRow(byte)/updateRow and call respective PL/SQL procedure to update row in table. As this is RowImpl class you will get all values using their getter methods.Check javadoc for information about these two methods.
  9. Override deleteRow(byte)/deleteRow and call respective PL/SQL procedure to delete row in table. As this is RowImpl class you will get all values using their getter methods. Check javadoc for information about these two methods.
Please let me know if I miss any points. I am happy to add here if it's relevant.

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.