How to Create Dynamic VO and Dynamic Table in OAF


This tutorial is comprising of Dynamic Table and Dynamic View Object Concepts.

I had a requirement of Displaying Records based on certain condition and that condition has to be dynamic ,So whenever that condition met records needs to be displayed in a table and Table also needs to be dynamic.

In the Following example i will be guiding you with simple queries for which Dynamic VO's will be created.

Below are the queries for which VO will be created.

Query 1 : select invoice_num from ap_invoices_all 

Query 2 : select user_name from fnd_user


We will be picking this query to display records on page on certain condition that's like

If you Select "I" it will use Invoice Table  and if you select "U" it will use FND_USER Table.

After entering the condition of page and submitting the GO button, You will be able to see records.

Below is the interpretation of the page.


















 Controller code for this


 /*===========================================================================+
  |   Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA    |
  |                         All rights reserved.                              |
  +===========================================================================+
  |  HISTORY                                                                  |
  +===========================================================================*/
 package xx.oracle.apps.ak.DynamicUpdatePG.webui;

 import oracle.apps.fnd.common.VersionInfo;
 import oracle.apps.fnd.framework.OAApplicationModule;


import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.server.OAViewDef;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
 import oracle.apps.fnd.framework.webui.OAPageContext;
 import oracle.apps.fnd.framework.webui.beans.OAWebBean;

import oracle.apps.fnd.framework.webui.beans.message.OAMessageStyledTextBean;

import oracle.apps.fnd.framework.webui.beans.table.OATableBean;



import oracle.jbo.AttributeDef;
import oracle.jbo.ViewObject;

import xx.oracle.apps.ak.DynamicUpdatePG.server.DynamicUpdateAMImpl;


/**
 * Controller for ...
 */
 public class DynamicCO extends OAControllerImpl
 {
   public static final String RCS_ID="$Header$";
   public static final boolean RCS_ID_RECORDED =
         VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

   /**
    * Layout and page setup logic for a region.
    * @param pageContext the current OA page context
    * @param webBean the web bean corresponding to the region
    */
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
     {
         super.processRequest(pageContext, webBean);  
            String xflag = "N";  
            String aparam = "";
            String voquery = "";
            if (pageContext.getTransactionValue("xflag") != null && !pageContext.getTransactionValue("xflag").equals(""))
                xflag = pageContext.getTransactionValue("xflag").toString();
          
            System.out.println("Flag="+ xflag);
            if ( xflag == "Y" )
            {
                if (pageContext.getTransactionValue("param") != null && !pageContext.getTransactionValue("param").equals(""))
                    aparam = pageContext.getTransactionValue("param").toString();
                  
                System.out.println("aparam="+ aparam);   
              
                if (aparam == "U" || aparam.equals("U"))
                {
                     voquery = "select user_name from fnd_user "; 
                }
                else if (aparam == "I" || aparam.equals("I"))
                {
                     voquery = "select invoice_num from ap_invoices_all ";
                }
                else
                {
                    voquery = "select user_name from fnd_user ";
                }
              
                System.out.println("voquery="+ voquery);
              
                AttributeDef[] attrdef = null;    
                //OAApplicationModule  oam = pageContext.getApplicationModule(webBean);

               DynamicUpdateAMImpl oam=(DynamicUpdateAMImpl)pageContext.getApplicationModule(webBean);
               if(oam!=null)
               {
                   OAViewDef viewdef=(OAViewDef)oam.getOADBTransaction().createViewDef();
                   viewdef.setSql(voquery);
                   OAViewObject vo=(OAViewObject)oam.createViewObject("xxVO",viewdef);
                   vo.executeQuery();
                   attrdef = vo.getAttributeDefs(); 
                   String colprompt = attrdef[0].getName();
                   System.out.println("colprompt"+colprompt);
                    //SampleVO1 is ViewObject Name
                     OATableBean tabbean = (OATableBean)createWebBean(pageContext,TABLE_BEAN,null,"table");     
                         tabbean.setID("TableBN");
                         tabbean.setNumberOfRowsDisplayed(10);
                         tabbean.setWidth("50%");
                         tabbean.setUserCustomizable(true);
                         tabbean.setViewUsageName("xxVO");     
                    
                         OAMessageStyledTextBean beans = (OAMessageStyledTextBean)createWebBean(pageContext,MESSAGE_STYLED_TEXT_BEAN,null,"beans");     
                         beans.setID("col"+colprompt+"0");
                         beans.setViewUsageName("xxVO");
                         beans.setViewAttributeName(colprompt);
                         beans.setLabel(colprompt);
                         beans.setUserCustomizable(true);
                         beans.setWrapEnabled(true);
                         beans.setDataType("VARCHAR2");
                    
                         tabbean.addIndexedChild(beans);
                         webBean.addIndexedChild(tabbean);
                      
               }
                   
                     
              /*  ViewObject vo = oam.findViewObject("xxVO");
            
                if(vo != null)    
                {
                    vo.remove();
                    vo = oam.createViewObjectFromQueryStmt("xxVO",voquery);
                }
                else
                {
                    vo = oam.createViewObjectFromQueryStmt("xxVO",voquery);
                }              
            
                                  
                                       
           OAViewObject vo12 = (OAViewObject)oam.findViewObject("xxVO");
           vo12.executeQuery();     
           attrdef = vo.getAttributeDefs(); 
           String colprompt = attrdef[0].getName();
           System.out.println("colprompt"+colprompt);      */
       
/*OAAdvancedTableBean tableBean = (OAAdvancedTableBean)webBean.findIndexedChildRecursive("DocumentTable");
           OASortableHeaderBean sortableHeaderBean =(OASortableHeaderBean)pageContext.getWebBeanFactory().createWebBean(pageContext, SORTABLE_HEADER_BEAN);
           sortableHeaderBean.setTextBinding("headerText");
           sortableHeaderBean.setSortableBinding("isSorted");

           OAColumnBean column1 = (OAColumnBean)createWebBean(pageContext, COLUMN_BEAN, null, "UseridCol");
           column1.setColumnHeader(sortableHeaderBean);
           DictionaryData data1 = new DictionaryData("headerText", "Document Browse");
           column1.setColumnHeaderData(data1);
       
           OAMessageStyledTextBean leaf1 = (OAMessageStyledTextBean)createWebBean(pageContext, MESSAGE_STYLED_TEXT_BEAN, null, "Leaf1");
          
                                   leaf1.setID("col"+colprompt+"0");
                                   leaf1.setViewUsageName("xxVO");
                                   leaf1.setViewAttributeName(colprompt);
                                   leaf1.setLabel(colprompt);
                                   leaf1.setUserCustomizable(true);
                                   leaf1.setWrapEnabled(true);
                                   leaf1.setDataType("VARCHAR2");
       
                                   tableBean.addIndexedChild(leaf1);
                                   //webBean.addIndexedChild(tableBean);*/

       }   
        
     }

     /**
      * Procedure to handle form submissions for form elements in
      * a region.
      * @param pageContext the current OA page context
      * @param webBean the web bean corresponding to the region
      */
     public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
     {
       super.processFormRequest(pageContext, webBean);  
       if(pageContext.getParameter("item2")!= null) // Go button
       {
           String param = pageContext.getParameter("item1");//To get text box value
           pageContext.putTransactionValue("xflag","Y");
           pageContext.putTransactionValue("param",param);
           pageContext.forwardImmediatelyToCurrentPage(null,true, "Y");
       }
      }

 }


Note : You can't write the code Dynamic VO creation and Dynamic Table creation in PROCESS FORM request method . As Oracle will never allow you to Modify Webean in Process Form Method



Comments

Popular posts from this blog

REST integration built-in OIC to read Large files with size more than 10MB

Basic Concepts of OAF (Oracle Applications FrameWork )