我的項目中出現錯誤。我正在使用Oracle ADF進行開發。這裏是摘要:迭代表格以獲取所有行並在adf中處理其中的一些錯誤
我有一個任務流,其中包含2個視圖,browseBusiness(devault視圖)和chooseBusiness。然後我有一個jspx頁面,其中包含任務流中的區域。
在browseBusiness中,我有2個按鈕,添加和刪除。如果我按下添加,那麼它會顯示chooseBusiness,並在其中一列顯示覆選框。我會檢查它的一些,當我點擊保存時,它應該迭代來知道我選擇哪一行,然後將它保存到數據庫。
我的問題是保存業務時無法迭代。這裏是我的代碼保存:
final RichTable table = this.getBisnisTabel();
final AppModuleImpl appModul =
(AppModuleImpl)ADFUtil.getApplicationModule("AppModuleDataControl");
FacesContext facesContext = FacesContext.getCurrentInstance();
VisitContext visitContext =
RequestContext.getCurrentInstance().createVisitContext(facesContext, null, EnumSet.of(VisitHint.SKIP_TRANSIENT,
VisitHint.SKIP_UNRENDERED),
null);
//ERROR IN HERE
UIXComponent.visitTree(visitContext, facesContext.getViewRoot(), new VisitCallback() {
public VisitResult visit(VisitContext context, UIComponent target) {
if (table != target) {
return VisitResult.ACCEPT;
} else if (table == target) {
//Here goes the Actual Logic
//for adding new Business
selectAllRowsInTable(table);
Iterator selection = table.getSelectedRowKeys().iterator();
while (selection.hasNext()) {
Object key = selection.next();
//store the original key
Object origKey = table.getRowKey();
try {
table.setRowKey(key);
Object o = table.getRowData();
JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)o;
Row row = rowData.getRow();
if (row.getAttribute
("Selected") != null) {
if ((Boolean)row.getAttribute("Selected"))
{
appModul.saveMTypeOfPolicyGrpBizCode(row.getAttribute("BizCode").toString());
row.setAttribute("Selected", false);
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
//restore original key
table.setRowKey(origKey);
}
}
}
return VisitResult.COMPLETE;
}
});
這是在表中選擇所有行的代碼:
public void selectAllRowsInTable(RichTable rt) {
RowKeySet rks = new RowKeySetImpl();
CollectionModel model = (CollectionModel)rt.getValue();
int rowcount = model.getRowCount();
for (int i = 0; i < rowcount; i++) {
model.setRowIndex(i);
Object key = model.getRowKey();
rks.add(key);
}
rt.setSelectedRowKeys(rks);
}
我很困惑,因爲當我在browseBusiness視圖中使用類似的代碼deleteBusiness,它運行非常流暢。這裏是代碼:
final RichTable table = this.getBizPolicyTable();
final AppModuleImpl appModul =
(AppModuleImpl)ADFUtil.getApplicationModule("AppModuleDataControl");
FacesContext facesContext = FacesContext.getCurrentInstance();
VisitContext visitContext =
RequestContext.getCurrentInstance().createVisitContext(facesContext,
null,
EnumSet.of(VisitHint.SKIP_TRANSIENT,
VisitHint.SKIP_UNRENDERED),
null);
//Annonymous call
UIXComponent.visitTree(visitContext, facesContext.getViewRoot(),
new VisitCallback() {
public VisitResult visit(VisitContext context,
UIComponent target) {
if (table != target) {
return VisitResult.ACCEPT;
} else if (table == target) {
//Here goes the Actual Logic
//for deleting multiple Business of Policy
CollectionModel cm =
(CollectionModel)getBizPolicyTable().getValue();
RowKeySet rowKeySet =
(RowKeySet)getBizPolicyTable().getSelectedRowKeys();
Object[] rowKeySetArray = rowKeySet.toArray();
for (Object key : rowKeySetArray) {
cm.setRowKey(key);
//store the original key
JUCtrlHierNodeBinding rowData =
(JUCtrlHierNodeBinding)cm.getRowData();
try {
Row row = rowData.getRow();
appModul.deleteMTypeOfPolicyGrpBizCode(row);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
//restore original key
}
}
appModul.getTypeOfPolicyBizCodeView3().executeQuery();
appModul.getTypeOfPolicyBizCodeView1().executeQuery();
}
return VisitResult.COMPLETE;
}
});
我的代碼有什麼問題嗎?感謝您的任何反饋:)
UPDATE: 嘗試調試我的項目。在此行中:
Object key = selection.next();
該值爲空。我不知道爲什麼..
而且我得到這個錯誤: 約束 「TYPE_OF_POLICY_BIZ_CODE_FK1」 後操作過程中違反了 「刪除」 使用SQL語句 「DELETE FROM M_BUSSINESS MBussiness WHERE BIZ_CODE = 1」。
在這裏我再次困惑,因爲我嘗試添加,而不是刪除值。我做錯了嗎?
問題是表是不允許選擇的,所以選中的行鍵是空的。我對嗎? – lucia