Reputation: 67
I am pretty new to Adf and am stuck in a place where I have 2 VO namely VO1 and Vo2. I have made a transient variable "TranVar" and view accessor in VO1 of VO2 as VA1. In the accessor of transient variable "TranVar", I am Programmatically accessing View Accessor VA1 because VA1 may result multiple rows, however, I need to send a single value in that transient variable. The code written in accessor of transient variable is :-
String flag = "false";
RowSetIterator rowSet = getVA1().createRowSetIterator(null);
Row row = null;
System.out.println("count-" + rowSet.getRowCount());
while (rowSet.hasNext()) {
if (row.getAttribute("IncludeFile").equals("true")) {
flag = "true";
}
}
return flag;
What my problem is that rowSet.getRowCount() is returning null that means it is not going inside while loop as their are no rows. However, the query I have written is true and returns value when executed in sql worksheet. Output is always coming false.
Kindly help, Question if seems confusing , please provide input so that I can return with same.
Upvotes: 0
Views: 8090
Reputation: 1804
You will get RowSetIterator
from accessor directly, if your view accessor type is <something> to *
.
Otherwise if your accessor type is <something> to 1
, then you will have Row
directly as result.
I assume that this code resides either in a ViewObjectRowImpl or EntityImpl type class:
// Why using String as flag, instead of Boolean or int?
String flag = "false";
// You don't need to create new rowset iterator
//RowSetIterator rowSet = getVA1().createRowSetIterator(null);
RowSetIterator rowSet = getVA1();
//FIXME: Avoid using System.out.println, use ADFLogger instead
System.out.println("count-" + rowSet.getRowCount());
while (rowSet.hasNext()) {
Row row = rowSet.next();
// Is this really string attribute? Better use CHAR or NUMBER for flags in DB
// Also when checking for string equality, put constant on the left side to avoid NPE
//if (row.getAttribute("IncludeFile").equals("true")) {
//Consider replacing string literals with constants
if ("true".equals(row.getAttribute("IncludeFile"))) {
flag = "true";
}
}
return flag;
Upvotes: 1
Reputation: 1657
As counter-intuitive as it might be for a java developer, accessors in ADF are not designed for referencing view objects from within other view objects. Accessors are internally represented by distinct view object instance than the one you have exposed in your AM.
For your purpose, you will need to get a reference of the view object instance though application module:
getApplicationModule.getVO1()
Another thing: careful with getRowCount(), especially over large datasets. getRowCount() does the counting in JVM memory, therefore it will fetch all your rows first.
Upvotes: 0