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.
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.
Hi Johny,
ReplyDeleteI often read your block and its really helpful thanks for your material and effort.