Displaying Data from Database


Displaying Data from Database in OAF

For displaying the data from the database first we have to.

Create the workspace and project.

Create the AM.

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

Next create one VO as follows.

Right click on the project select new. Then ADF Business Component Then View Object and select OK.



After that u will see the welcome window just click next.

In next window give the View Object Name.

Name:- (DataDisplayVO).

Package:- will come by default.

Click next.



After that just click next, next and in step 5 of 8 write the sql statement for the VO.

select * from fwk_tbx_employees




Click next, next and in the step 8 of 8 just check the generate java file.




Click next and finish.

Next we have to attach this VO to the AM.

Right click on AM select edit AM.

In that select the VO and move that as shown below.



Click Apply and OK.

Next come to the page create on button

Name :- Get Details.

Next create one table region to display the data.

Right click on main region select new Region using wizard.



Next u will get one welcome window just click next .

In next step select your AM from the list and it will show the VO attached to it.





Click next .

In next step 

Region ID :- your View instance name(DataDisplayVO1).

Region Style:-  Select table (table).



Click next ..

In next step move which ever attributes u want to display.



Click next,  next and finish.

Now we have to create one controller.

Right click on main region select set new controller.




Next give the name for the controller.

Package:- by default two webui will come just remove one webui.

Class Name:- Give the name (DataDisplayCO).



For displaying the data write the following code in the process form request.




/*For Copy Paste*/

  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
      if(pageContext.getParameter("Go")!=null)
        {
                  /* The below code line is used to initialize the application module */
        OAApplicationModule am=(OAApplicationModule)pageContext.getApplicationModule(webBean);
      /* The below code line is used to initialize VO*/
        OAViewObject vo=(OAViewObject)am.findViewObject("DataDisplayVO1");
      /* DataDisplayVO1 is the instance name in AM which is the original name of the VO */
           vo.executeQuery();
         }
      }


Next run the page to get the desired output.

After clicking the Get Details button it will display the details.



If u want to clear the data den first create one button called “Clear” and write the following code in processFormRequest.




/*For Copy Paste*/

  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
   
      /* The below code line is used to initialize the application module */
        OAApplicationModule am=(OAApplicationModule)pageContext.getApplicationModule(webBean);
      /* The below code line is used to initialize VO*/
        OAViewObject vo=(OAViewObject)am.findViewObject("DataDisplayVO1");
      /* DataDisplayVO1 is the instance name in AM which is the original name of the VO */
      if(pageContext.getParameter("Go")!=null)
        {
             vo.setWhereClause(null);
              vo.setWhereClause("1=1");

           vo.executeQuery();
         }
       /*To clear the data form the table region */ 
      if(pageContext.getParameter("Clear")!=null)
      {
      vo.setWhereClause(null);
       vo.setWhereClause("1=2");
       vo.executeQuery();
      }
}

Run the page to see the output.


5 comments:

  1. Hi, how to display data when we pass in a parameter from other page?
    Can we display data without having to press Go button etc?

    Thanks

    ReplyDelete
    Replies
    1. Yes we can. Execute the vo in process request.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. hi, how to display the data after uploading the excel in oaf page., am able to load the excel file and it is storing in database table, now my concern is whenever user clicks the upload button data should display in oaf page in the below region., is that possible., if possible please help me on this

      Delete
  3. Hi.. I am getting error of null pointer exception on vo.executequery(), either I am writing the code in processRequest() ot processFormRequest. Please suggest

    ReplyDelete