Showing posts with label Dynamic VO. Show all posts
Showing posts with label Dynamic VO. Show all posts

Friday, 22 May 2015

ADF/OAF: How to create Dynamic View Object in Controller in Oracle Application Framework

In this post I will give sample code to to create a View Object dynamically/programatically/runtime in Oracle Applications Framework in a Controller. 
Applicable to ADF Web Applications also.

 import oracle.jbo.Row;  
 import oracle.jbo.ViewObject;  
 import oracle.apps.fnd.framework.OAApplicationModule;  
 public void processRequest(OAPageContext pageContext, OAWebBean webBean) {  
      super.processRequest(pageContext, webBean);  
      OAApplicationModule appModule = pageContext.getApplicationModule(webBean);  
      if(appModule != null)   
      {  
           ViewObject dynamicVO = appModule.findViewObject("DynamicVO");  
           if(dynamicVO == null)   
           {  
                String querySql = "select user_id, user_name from fnd_user where rownum < 5";  
                dynamicVO = appModule.createViewObjectFromQueryStmt("DynamicVO",querySql);  
           }  
           if(dynamicVO != null)   
           {  
                dynamicVO.setWhereClause(null);  
                dynamicVO.setWhereClauseParams(null);  
                dynamicVO.executeQuery();  
                for(Row dynamicVORow = dynamicVO.first(); dynamicVORow != null; dynamicVORow = dynamicVO.next()) {  
                     System.out.println("----------");  
                     System.out.println("User ID:" + dynamicVORow.getAttribute(0));  
                     System.out.println("User ID:" + dynamicVORow.getAttribute("USER_ID"));  
                     System.out.println("User Name:" + dynamicVORow.getAttribute(1));  
                     System.out.println("User Name:" + dynamicVORow.getAttribute("USER_NAME"));  
                }  
           }  
      }  
 }  
You can modify the querySql as per your need. You add additional whereclause as you want. You can also create without whereclause and add dynamic whereclause if needed.

Attributes can be accessed either with the position or using the uppercase of the column name specified in the query.

Feel free to point out if anything is missing/wrong in this blog.

Saturday, 28 March 2015

OAF: Sample Code to create Dynamic VO in OA Framework

In some cases, we need to create Dynamic View Object in OA Framework. The sample code to create a dynamic View Object is given below.

 ViewObject dynamicViewObject = appModule.findViewObject("XXDynamicVO");  
 if(dynamicViewObject == null)  
 {  
  String voQuery = " SELECT USER_NAME " +  
                                " FROM fnd_users FU " +  
                                " WHERE FU.user_id = :1 ";  
  customViewObject = appModule.createViewObjectFromQueryStmt("XXDynamicVO",voQuery);  
 }  
 if(customViewObject != null)  
 {  
  customViewObject.setWhereClause(null);  
  customViewObject.setWhereClauseParams(null);  
  customViewObject.setWhereClauseParam(0,userID);  
  customViewObject.executeQuery();  
  Row customViewObjectRow = customViewObject.first();  
  if(customViewObjectRow != null)  
  {  
       String userName = (String)customViewObjectRow.getAttribute(0);  
       writeLog(pageContext,"UserName:" + userName);  
  }  
 }  

Feel free to point out if anything is missing/wrong in this blog.