亲爱的ADF专家,
我使用以下托管bean代码将新行插入主详细信息关系的详细信息表中。只要用户单击表中的行作为SelectionListener事件处理程序,就会使用“insertNewReturnReason”。它应该扮演createInsert绑定操作的角色,除了它尝试回滚之前创建的行,然后在主迭代器的新id(“AstAssetVOIter”)下插入一个新行。我有的另一个事件监听器是“saveAssetReturn”,它应该提交更改。
我遇到的问题是“insertNewReturnReason”,它首先进行回滚,然后在详细信息表中插入新行。由于某种原因,表单保持警告需要字段,这是另一个表中的外键。
相同的代码在另一个项目中运行正常,我没有遇到任何问题,我改变的唯一内容是迭代器的名称和视图对象。
我已将按钮的直接属性设置为true。
如果您有任何想法,请告诉我。
谢谢,
package com.asrandisheh.mis.asset.viewcontroller;
import javax.faces.event.ActionEvent;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.jbo.Row;
//import util.JSFUtils;
import com.asrandisheh.mis.asset.viewcontroller.JSFUtils;
import org.apache.myfaces.trinidad.event.SelectionEvent;
import oracle.binding.BindingContainer;
import oracle.jbo.ViewObject;
import oracle.binding.OperationBinding;
import oracle.jbo.Key;
public class AssetReturn {
public AssetReturn() {
super();
}
public void insertNewReturnReason(SelectionEvent selectionEvent) {
//
System.out.println("Method Call: insertNewReturnReason");
// maintain the makecurrent behavior
JSFUtils.resolveMethodExpression("#{bindings.AstAssetsVO1.collectionModel.makeCurrent}", null,
new Class[]{SelectionEvent.class}, new Object[]{selectionEvent});
// Set the binding context
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = bctx.getCurrentBindingsEntry();
// get the current row for AST_ASSET table
DCIteratorBinding astAssetsVOIterator = (DCIteratorBinding) bindings.get("AstAssetsVOIterator");
Key parentKey = astAssetsVOIterator.getCurrentRow().getKey();
//You can add your operation code here, i have used simple Cancel operation with Rollback and Execute
OperationBinding ob= bindings.getOperationBinding("Rollback");
ob.execute();
// OperationBinding ob1= bindings.getOperationBinding("Execute");
// ob1.execute();
//Set again row key as current row
astAssetsVOIterator.setCurrentRowWithKey(parentKey.toStringFormat(true));
Row assetRow = astAssetsVOIterator.getCurrentRow();
// print out the current ID
System.out.println(assetRow.getAttribute("Id"));
// get the AstAssetReturnsVOIterator and create a new row with default values
DCIteratorBinding astAssetReturnsVOIterator = (DCIteratorBinding) bindings.get("AstAssetReturnsVOIterator");
ViewObject assetReturnVO = astAssetReturnsVOIterator.getViewObject();
assetReturnVO.executeEmptyRowSet();
// pre-set values for ast_asset_return
Row assetReturnRow = assetReturnVO.createRow();
assetReturnRow.setAttribute("AsetId", assetRow.getAttribute("Id"));
assetReturnRow.setAttribute("AsrtDate", "1395/12/31");
assetReturnRow.setAttribute("Stat", 1);
// switch the status to "RETURNED"
// assetRow.setAttribute("Status", "RETURNED");
assetReturnVO.insertRow( assetReturnRow );
}
public void saveAssetReturn(ActionEvent actionEvent) {
// Set the binding context
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = bctx.getCurrentBindingsEntry();
// get the current row for AST_ASSET table
DCIteratorBinding astAssetsVOIterator = (DCIteratorBinding) bindings.get("AstAssetsVOIterator");
astAssetsVOIterator.getCurrentRow().setAttribute("Status", "Returned");
OperationBinding ob = bindings.getOperationBinding("Commit");
ob.execute();
}
//
// public void saveAssetReturn(ActionEvent actionEvent) {
// // Add event code here...
// }
}