我的项目出现错误。我正在使用 Oracle ADF 进行开发。这是简短的:
我有一个任务流,其中包含 2 个视图,browseBusiness(devault 视图)和 chooseBusiness。然后我有一个 jspx 页面,其中包含来自任务流的区域。
在browseBusiness 中,我有2 个按钮,添加和删除。如果我按添加,那么它将显示选择业务,其中一列中有一个复选框。我会检查其中的一些,当我单击保存时,它应该迭代以知道我选择了哪一行,然后将其保存到数据库中。
我的问题是它在保存业务时无法迭代。这是我要保存的代码:
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 视图中使用类似的代码删除Business 时,它运行得非常流畅。这是代码:
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;
}
});
我的代码有什么问题吗?感谢您的任何反馈:)
更新:尝试调试我的项目。在这一行:
Object key = selection.next();
该值为空。我不知道为什么。。
我收到此错误:在使用 SQL 语句“DELETE FROM M_BUSSINESS MBussiness WHERE BIZ_CODE=:1”后操作“删除”期间违反了约束“TYPE_OF_POLICY_BIZ_CODE_FK1”。
在这里我再次感到困惑,因为我尝试添加而不是删除值。我做错了吗?