Switcher working in hGrid Apparently, this is a compatibility feature of switcher and hGrid. Solution:
1) Without changing the SQL in VO, create a transient attribute with a name, for example, swTran (Type: String, Updatable: Always);
2) In the VORowImpl module, modify the getter function so that it returns the value of our parameter depending on the attribute myCond:
public String getSwTran() {
Number i = getmyCond();
String cf = "";
if (i.intValue() == 0){
return cond1;
}else{
return cond2;
}
}
hGrid does not redraw when filtering data Solution: move all the logic of wrapping VO into conditions in processRequest. And, as recommended in the guide, after calling the method of the same name of the parent class, specify
OAHGridBean hGrid = (OAHGridBean)
webBean.findIndexedChildRecursive("Grid");
if (hGrid != null) {
hGrid.prepareForRendering(pageContext);
hGrid.setAutoQuery(false);
}
Using attributes from different levels VO in bean attributes (for example, building Destination URI) Three conditions must be met: 1) the attributes used are present at ALL levels, where they do not have physical meaning, make them Transient; 2) parameter aliases must be identical case-sensitive; 3) in the bean attributes View Instance and View Attribute should be written any level and parameter having physical meaning.
Recursive creation of hGrid levels If the entity is tied to itself by id = parent_id, then automatic construction of hGrid levels may be required. Solution:
1. Create VL with relation id = parent_id with relationship 0..1 to *;
2. Add a second instance of the lower-level VO in AM through a link with the created VL
3. We construct the hGrid tree in PG
Here CommentLevel is the lower-level branch with View Instance = Comment3VO1, ChildCommentLevel is the recursively created branch with View Instance = Comment3VO2, CommentsLevel is the node with View Link Instance = CommentRecursiveVL1. Special attention should be paid to the RecursiveLink node, where View Link Instance = CommentRecursiveVL1. For it, you also need to specify the parameter Ancestor Node = /oracle/apps/.../path to package/. - this is necessary for looping when building new levels. In our case, = CommentsLevel.
Unconditional page navigation pageContext.forwardImmediately(
"OA.jsp?page=/oracle/apps/xxx/xxx1/webui/MyPG",
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
true, // retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
Page redraw with hashmap HashMap params = new HashMap(10);
params.put("wPrm1", pageContext.getParameter("prm1"));
params.put("wPrm2", pageContext.getParameter("prm2"));
params.put("wPrm3", pageContext.getParameter("prm3"));
pageContext.forwardImmediatelyToCurrentPage(
params,
false,
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
...
public void processRequest{
...
(OAPageContext pageContext, OAWebBean webBean)
pageContext.getParameter("wPrm1"));
...
}
Exception handling try{
OAApplicationModule am = pageContext.getApplicationModule(webBean);
OADBTransaction tran = (OADBTransaction)am.getTransaction();
prm = tran.getMyPRM();
}
catch (SQLException e) {
throw OAException.wrapperException(e);
}
invokeMethod with full parameters OAApplicationModule am = pageContext.getApplicationModule(webBean);
Serializable[] prm_values = {myNum, myStr};
Class[] prm_classes = {Number.class, String.class};
am.invokeMethod("MyProc", prm_values, prm_classes);
Wrapping VO in constraints public void initQuery(Number Id, String Str) {
setWhereClause(null);
setWhereClauseParams(null);
setWhereClause("ent_id = :1 and ent_name = :2");
setWhereClauseParam(0, Id);
setWhereClauseParam(1, Str);
executeQuery();
}
Programmatic title change for webbean String someTitle = "title1";
((OAPageLayoutBean)webBean).setTitle(someTitle);
Calling a DB procedure OADBTransaction tran = getOADBTransaction();
OracleCallableStatement cStmt = null;
StringBuffer callSt = new StringBuffer();
callSt.append("begin XXX_PKG.set_params(");
callSt.append("pv_name => :1, ");
callSt.append("pv_id => :2, ");
callSt.append("pv_date => :3)");
callSt.append("; end;");
try {
cStmt = (OracleCallableStatement)
tran.createCallableStatement(callSt.toString(),
tran.DEFAULT);
cStmt.setString(1, prmUser);
cStmt.setNUMBER(2, prmID);
cStmt.setString(3, prmDate);
cStmt.execute();
cStmt.close();
}
catch (SQLException sqle) {
throw OAException.wrapperException(sqle);
}
Centering column content (hGrid) private void getColCentered(OAPageContext pageContext,
OAWebBean webBean, OAHGridBean hGrid)
DataObjectList columnFormats = hGrid.getColumnFormats();
DictionaryData columnFormat = null;
int childIndex[] =
new int[] { pageContext.findChildIndex(hGrid, "Column1"),
pageContext.findChildIndex(hGrid, "Column2"),
pageContext.findChildIndex(hGrid, "Column3"),
};
for (int i: childIndex) {
columnFormat = (DictionaryData)columnFormats.getItem(i);
columnFormat.put(COLUMN_DATA_FORMAT_KEY, ICON_BUTTON_FORMAT);
}
}
Dynamic creation of View Object StringBuffer strBuf = new StringBuffer();
strBuf.append("select p from (select 0 p from dual ");
strBuf.append("union ");
strBuf.append("select 1 from dual)");
ViewObject myVO = am.createViewObjectFromQueryStmt("myVO", strBuf.toString());
myVO.setWhereClause("p = :1");
myVO.setWhereClauseParam(0, "0");
myVO.executeQuery();
myVO.first();
OAMessageChoiceBean mcBean = (OAMessageChoiceBean)webBean.findChildRecursive("Test");
mcBean.setValue(pageContext, (String)myVO.getCurrentRow().getAttribute(0));
myVO.remove();
Converting a string to oracle.jbo.domain.Date object import java.text.SimpleDateFormat;
import java.text.DateFormat;
import oracle.cabo.ui.data.DataObjectList;
import oracle.cabo.ui.data.DictionaryData;
public void dateTest(){
String dateStr = "11.01.2013";
DateFormat df;
df = new SimpleDateFormat("dd.MM.yyyy");
java.util.Date tmp = null;
tmp = df.parse(dateStr);
oracle.jbo.domain.Date resDate = new oracle.jbo.domain.Date(new java.sql.Date(tmp.getTime()));
}
Clearing VO dataset (iterator) public void clearVO(){
MyVOImpl MyVO = getMyVO1();
int rowCount = MyVO.getRowCount();
RowSetIterator deleteIter = MyVO.createRowSetIterator("deleteIter");
if (rowCount > 0) {
deleteIter.setRangeStart(0);
deleteIter.setRangeSize(rowCount);
for (int i = rowCount - 1; i > -1; i--) {
MyVORowImpl row = (MyVORowImpl)deleteIter.getRowAtRangeIndex(i);
row.remove();
}
}
deleteIter.closeRowSetIterator();
}
Clearing VO dataset (method) singleVO.executeEmptyRowSet();
Searching for a record in VO CausesVOImpl causeVO = getCausesVO1();
if (!causeVO.isPreparedForExecution()){
causeVO.setMaxFetchSize(0);
}
causeVO.executeQuery();
causeVO.setRangeStart(0);
causeVO.setRangeSize(causeVO.getRowCount());
Number causeId = new Number(1);
OADBTransaction transaction = getOADBTransaction();
Key keyCauseId = new Key(new Object[] {causeId});
// 1 - maximum number of returned records
Row causes[] = causeVO.findByKey(keyCauseId, 1);
if (causes != null && causes.length > 0) {
CausesVORowImpl causeRowVO = (CausesVORowImpl)causes[0];
...
}
Building master-detail in table component 1) Add an Expand attribute of type String to the parent VO and set it as a constant 'N' in the query. The detail will be displayed only for rows where (Expand is not null). N - the detail is collapsed by default, Y - expanded;
2) Create a View Link (MyVL) to link the data, add it and the relationship with the child table to the Application Module;
3) Parent table: parameter Detail View Attribute = Expand;
4) Create a detail bean: right-click on the parent table bean - New - detail. In the table components - detail hierarchy, create a table layout, and within it, create a table. The first one is optional but may be needed to add control elements to the detail;
5) Child table: parameter Detail View Attribute = , View Link Instance =
Alternative method for programmatically linking master and detail:
public void setMasterDetailLink(OAPageContext pageContext, OAWebBean webBean) {
OATableBean masterTable = (OATableBean)webBean.findChildRecursive("MasterTable");
if (masterTable != null) {
masterTable.setAttributeValue(CHILD_VIEW_ATTRIBUTE_NAME, "DetailId");
masterTable.setAttributeValue(VIEW_LINK_NAME, "MyVL1");
masterTable.setAllDetailsEnabled(true);
}
OATableBean detailTable = (OATableBean)webBean.findChildRecursive("DetailTable");
if (detailTable != null) {
detailTable.setAttributeValue(CHILD_VIEW_ATTRIBUTE_NAME, "MasterId");
detailTable.setAttributeValue(VIEW_LINK_NAME, "MyVL1");
detailTable.clearCache(pageContext);
}
}
Formatting using the Formatter interface private void setColumnsFormat(OAPageContext pageContext, OAWebBean webBean, OAHGridBean hGrid){
int i;
String format = "#,##0;-#,##0";
ArrayList columns = new ArrayList();
Formatter formatter = new OADecimalValidater(format, format);
String columnNames[] = new String[] {"Col1", "Col2", "Col3"};
for (String str: columnNames){
OAMessageStyledTextBean col = (OAMessageStyledTextBean)
webBean.findChildRecursive(str);
if (col != null) columns.add(col);
}
for (i = 0; i
Clearing VO when using retainAM=Y A common issue arises: when using retainAM (preserving the application module state), the master-detail in table beans does not reflect the current data state. To clear the datasets in all VOs associated with AM, it is advisable to use the method
am.clearVOCaches(null,Boolean.TRUE);
Centering column content (table) private void alignCenter(OAPageContext pageContext, OAWebBean webBean) {
OATableBean versionTable = (OATableBean)webBean.findChildRecursive("SearchVO1");
versionTable.prepareForRendering(pageContext);
DataObjectList columnFormats = (DataObjectList)versionTable.getColumnFormats();
DictionaryData columnFormat = null;
//
int childIndex = pageContext.findChildIndex(versionTable, "imgEdit");
columnFormat = (DictionaryData)columnFormats.getItem(childIndex);
columnFormat.put(COLUMN_DATA_FORMAT_KEY, ICON_BUTTON_FORMAT);
//
childIndex = pageContext.findChildIndex(versionTable, "imgRemove");
columnFormat = (DictionaryData)columnFormats.getItem(childIndex);
columnFormat.put(COLUMN_DATA_FORMAT_KEY, ICON_BUTTON_FORMAT);
}