How to dynamically add view attribute to existing VO
Following code can be used for dynamically adding new view attribute to existing standard VO
OAViewObject stdVO = (OAViewObject)am.findViewObject("OracleStdVO");
if (stdVO != null) {
try {
String transientAttr =
stdVO.findAttributeDef("AdditionalInfo").toString();
} catch (Exception e) {
stdVO.addDynamicAttribute("AdditionalInfo");
pageContext.writeDiagnostics(this,"<<<Added dynamic transient attribute>>>",OAFwkConstants.STATEMENT);
}
}
How to dynamically create query based view object
String requisitionLineId = 123; // Need to pull up dynamically
String requisitionHeaderId = 234; // Need to pull dynamically
// Create view object(only if doesnot exist) for getting ATTRIBUTE11 from PO_REQUISITION_LINES_ALL table
oracle.jbo.server.ViewObjectImpl customVO = (ViewObjectImpl)am.findViewObject("POReqVO");
if(customVO==null){
pageContext.writeDiagnostics(this,"<<<Inside customVO is null>>>",OAFwkConstants.STATEMENT);
// Define query.
String retnSqlStr = "select ATTRIBUTE11 from PO_REQUISITION_LINES_ALL WHERE REQUISITION_LINE_ID =:1 AND REQUISITION_HEADER_ID = :2";
customVO = (ViewObjectImpl)am.createViewObjectFromQueryStmt("POReqVO", retnSqlStr);
}
String attribute11 = null;
pageContext.writeDiagnostics(this,"<<<Created customVO>>>"+customVO,OAFwkConstants.STATEMENT);
customVO.setWhereClause(null);
customVO.setWhereClauseParams(null);
// Execute Query for this Requisition line
customVO.setWhereClauseParam(0,requisitionLineId);
customVO.setWhereClauseParam(1,requisitionHeaderId);
customVO.executeQuery();
int rowCnt = customVO.getRowCount();
pageContext.writeDiagnostics(this,"<<<Executed Retention Query RowCount = >>>"+rowCnt,OAFwkConstants.STATEMENT);
customVO.setRangeSize(rowCnt);
Row retnRows[] = customVO.getAllRowsInRange(); //there will be only one row but will loop
// Get value after query execution
for(Row retnRow:retnRows){
attribute11 = (String)retnRow.getAttribute(0);
pageContext.writeDiagnostics(this,"<<<Inside retention query row loop retention = >>>"+retention,OAFwkConstants.STATEMENT);
}