Inserting Data into Database


Data Entry page in OAF


For data entry

First create one workspace and project.

Create the AM.

Create the page and attach the AM to the main region of the page.

For Data Entry or any DML operation we need to create the Entity Object.

Steps to create the EO.

Right click on the project select new and then ADF Business Component And Entity Object.



Click ok, After that u will get the welcome window just click next.

In next window

Package :- Select your package from the list. And add the schema.server.
(sangu.oracle.apps.po.DataDisplayPRJ.schema.server)

Schema Object :- Select the table, view ,synonyms or materialized view on which u want to create the EO 
                            Below that click the respective check box den only u will get them in the list.




Click next, next in step 3 of 5 if u want u can set the attributes like primary key etc.




Click next  there u check in generate java all the check boxes as shown below.




Click next . In next if u want u can create the VO based on this EO directly.

Just give the VO name. then click next next and finish.




After creating the EO and VO u just attach this VO to AM.




Next come to the page and create one messageComponentLayout Region in that create the items for which u want to insert the data.

And create two submitButtons for saving the data and clearing the data.




Now set the following properties for each item except submitButton

View Instance:- Select the view instance from the lov



View Attribute:- Select the attribute u want, from the lov.




And set the proper data type and prompt for each item.

If u want the space between the buttons then create one item set the style as spacer
And set the property.

Width: Give some distance (20)



After completing the page structure now write the following code in the java file of the AM.

Select the AM in structure it will show the DataDisplayAMImpl.java just double click on that.
U will get the window.

In that java file create one method for inserting the data.



/*for copy paste*/

    public void insertData()
    {
        /*Write the following code to initialize the VO*/
        OAViewObject vo = getFwkTbxEmployeesEOVO1();
              if(!vo.isPreparedForExecution())
              {
                vo.executeQuery();
              }
              /*write the following code to create one empty row */
              OARow row=(OARow)vo.createRow();
              /*write the following to isert the data*/
              vo.insertRow(row);
    }


Create another method for saving the data.



/*for copy paste*/

    public void Save()
        {
         getOADBTransaction().commit();
        }


After creating the methods in AM java file create one controller and call these methods in that.

Write the following code in processRequest of the controller.



 /*for copy paste*/

 public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
        /*for initializing the AM */
        OAApplicationModule                                                                                                                                            am=(OAApplicationModule)pageContext.getRootApplicationModule();
      
 /*invoke the method which u write for inserting data */
        am.invokeMethod("insertData");
      }


Write the following in the processFormRequest of the controller.



/*for copy paste*/


  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
   
      /*for initializing the AM */
            OAApplicationModule                                                                                                                                               am=(OAApplicationModule)pageContext.getRootApplicationModule();
           
         


  if(pageContext.getParameter("Save")!=null)
                {
                 /*invoke the method which u write for saving the data */
                  am.invokeMethod("Save");
                  /* for throwing confirmation message*/
                  throw new OAException("Data Entered Successfully”, 
                                                                        OAException.CONFIRMATION);
                }
      }      
     

Run the page to get the output.





After clicking the Clear button if u want to clear the fields write the following code in processFormRequest.



/*for copy paste*/


       if(pageContext.getParameter("Clear")!=null)
      {
      OAMessageTextInputBean msb1 = (OAMessageTextInputBean)webBean.findChildRecursive("EmployeeId");
      msb1.setValue(pageContext,null);
      OAMessageTextInputBean msb2 = (OAMessageTextInputBean)webBean.findChildRecursive("Title");
      msb2.setValue(pageContext,null);
      OAMessageTextInputBean msb3 = (OAMessageTextInputBean)webBean.findChildRecursive("FirstName");
      msb3.setValue(pageContext,null);
      OAMessageTextInputBean msb4 = (OAMessageTextInputBean)webBean.findChildRecursive("LastName");
      msb4.setValue(pageContext,null);
      OAMessageTextInputBean msb5 = (OAMessageTextInputBean)webBean.findChildRecursive("PositionCode");
      msb5.setValue(pageContext,null);
      OAMessageTextInputBean msb6 = (OAMessageTextInputBean)webBean.findChildRecursive("Salary");
      msb6.setValue(pageContext,null);
      }  

15 comments:

  1. Very well Explained.......Looking forward more.......

    ReplyDelete
  2. How to insert employee id from sequence??

    ReplyDelete
  3. Hi Justin,
    Go through the below link,

    http://yesyespatil.blogspot.in/2013/10/invoking-sequence-in-oaf-page.html

    --Sangu

    ReplyDelete
  4. how can we update multiple Rows at a time

    ReplyDelete
  5. Hi Vamshi,

    To update multiple records at a time provide one check box column in search region to select multiple records
    and use the array to collect all the records
    and create a procedure to update the records and pass the array as a parameter to that procedure.

    ReplyDelete
  6. hi , i tried this but this errorcome ( Error: Stale Data




    The requested page contains stale data. This error could have been caused through the use of the browser's navigation buttons (the browser Back button, for example).

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Sangu,

    Please help me out from this error, i followed your steps and also changed bind style to "oracle positional" after running Page i got the below result:


    Error Page

    Exception Details.
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT cesEO.EMPNO, cesEO.ENAME, cesEO.JOB, cesEO.MGR, cesEO.HIREDATE, cesEO.SAL, cesEO.COMM, cesEO.DEPTNO FROM EMP1 cesEO
    at oracle.apps.fnd.framework.OAException.wrapperException(Unknown Source)
    at oracle.apps.fnd.framework.OAException.wrapperException(Unknown Source)
    at oracle.apps.fnd.framework.OAException.wrapperInvocationTargetException(Unknown Source)
    at oracle.apps.fnd.framework.server.OAUtility.invokeMethod(Unknown Source)
    at oracle.apps.fnd.framework.server.OAUtility.invokeMethod(Unknown Source)
    at oracle.apps.fnd.framework.server.OAApplicationModuleImpl.invokeMethod(Unknown Source)
    at cesPRJ.oracle.apps.po.ces.webui.ces1CO.processRequest(ces1CO.java:38)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.beans.OABodyBean.processRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at _OA._jspService(_OA.java:71)
    at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
    at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:462)
    at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
    at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
    at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
    at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
    at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    at java.lang.Thread.run(Thread.java:595)
    ## Detail 0 ##
    java.sql.SQLException: ORA-00942: table or view does not exist

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:138)

    ReplyDelete
    Replies
    1. The error msg saying that ( table or view does not exist)
      please check.

      Delete
  9. Hi
    We are following your step and facing below error " Error(65,7): method getTransaction() not found in class india.oracle.apps.po.india.webui.xxInsertDemoCO"

    Can you please help us....
    Thanks

    ReplyDelete
    Replies
    1. Write the message in AM
      or if you want to write in CO refer below code

      OADBTransaction tr = getOADBTransaction();
      tr.commit;

      Delete
  10. How can i validate advance table region data against a procedure before inserting into database.

    ReplyDelete
  11. like i have 10 columns(like source_project_name,dest_project_name,quantity and so on....) in advance table region at line level and have multiple rows but when i click the save button
    all the rows for every column should be validated before inserting .
    E.g when i put the quantity , the value of quantity will go into that procedure and it will check whether it is available or not.

    I have made that procedure for validation but don't know how to pass those values in a loop for every row with each column.

    Please help for the same...

    ReplyDelete
  12. How to insert data in multiple table using oaf

    ReplyDelete