2015-06-03 59 views
0

我對Adf來說很新,並且陷入了我有2個VO(VO1和Vo2)的地方。我做了一個瞬態變量「TranVar」,並將VO2的VO1中的訪問器視爲VA1。 在瞬變變量「TranVar」的訪問器中,我以編程方式訪問View Accessor VA1,因爲VA1可能會導致多行,但是,我需要在該瞬變變量中發送單個值。 寫在短暫的變量的訪問代碼是: -以編程方式訪問視圖訪問器並使用RowSetIterator

 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; 

我的問題是什麼是rowSet.getRowCount()方法返回null,這意味着它們沒有排它不會內部while循環。但是,我寫的查詢是真實的,並且在sql工作表中執行時返回值。 輸出總是出錯。

請幫助,問題如果似乎混淆,請提供輸入,以便我可以返回相同。

回答

0

與AD開發者可能不太一樣,ADF中的訪問器並不是用來引用其他視圖對象中的視圖對象。 訪問者在內部由不同於您在AM中公開的視圖對象實例表示。

你的目的,你需要獲取視圖對象實例,雖然應用模塊的參考:

getApplicationModule.getVO1() 

另一件事:小心getRowCount(),尤其是在大型數據集。 getRowCount() does the counting in JVM memory,因此它會首先獲取所有行。

1

如果您的查看存取器類型爲<something> to *,您將直接從存取器獲得RowSetIterator
否則,如果您的訪問者類型爲<something> to 1,那麼您將直接得到。

我假定該代碼駐留在任一ViewObjectRowImpl或EntityImpl類型類:

// 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;