我對ADF很新穎,並且仍然獲得實踐經驗。如何在第一頁加載時按下頁面中列表/表格的第一項?
當用戶最初打開JSFF頁面時,我只想調用一次託管bean方法。該方法綁定到頁面上的表的SelectionListener。我需要迭代器可用,因爲該處理程序執行一些CRUD操作(以下是方法「insertNewReturnReason」的代碼)。
我已經閱讀了Shay Shmeltzer的link,我很好奇我怎樣才能以相同的方式進行編程。
請讓我知道。
謝謝你和你的幫助,非常感謝。
問候
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 com.asrandisheh.mis.asset.model.viewobject.AstAssetReturnsVORowImpl;
import com.asrandisheh.mis.asset.viewcontroller.JSFUtils;
import javax.faces.context.FacesContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.jbo.server.Entity;
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) {
// Maintain the makecurrent behavior
JSFUtils.resolveMethodExpression("#{bindings.AstAssetsVO.collectionModel.makeCurrent}", null,
new Class[]{SelectionEvent.class}, new Object[]{selectionEvent});
// Get 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();
//Rollback any previously created row
OperationBinding ob= bindings.getOperationBinding("Rollback");
ob.execute();
//Set again row key as current row
astAssetsVOIterator.setCurrentRowWithKey(parentKey.toStringFormat(true));
// 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();
Row assetRow = astAssetsVOIterator.getCurrentRow();
assetReturnRow.setAttribute("AsetId", assetRow.getAttribute("Id"));
assetReturnRow.setAttribute("AsrtDate", "1395/12/31");
assetReturnRow.setAttribute("Stat", 0);
// insert the new row
assetReturnVO.insertRow(assetReturnRow);
}
public void saveAssetReturn(ActionEvent actionEvent) {
// Get the bindings
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();
}
}
編輯:如果我使用的方法調用的活動作爲初始活動我得到空指針,當我嘗試訪問的ViewObject的迭代器。以防萬一,我已經標記了空白指針異常的線。
public void assetReturnInitialization() {
// Get 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");
// get the AstAssetReturnsVOIterator and create a new row with default values
DCIteratorBinding astAssetReturnsVOIterator = (DCIteratorBinding) bindings.get("AstAssetReturnsVOIterator");
ViewObject assetReturnVO = astAssetReturnsVOIterator.getViewObject(); // NULL POINTER EXCEPTION OCCURS HERE
assetReturnVO.executeEmptyRowSet();
System.out.println("assetReturnInitialization 40");
// pre-set values for ast_asset_return
Row assetReturnRow = assetReturnVO.createRow();
Row assetRow = astAssetsVOIterator.getCurrentRow();
System.out.println("assetReturnInitialization 50");
assetReturnRow.setAttribute("AsetId", assetRow.getAttribute("Id"));
assetReturnRow.setAttribute("AsrtDate", "1395/12/31");
assetReturnRow.setAttribute("Stat", 0);
System.out.println("assetReturnInitialization 60");
// insert the new row
assetReturnVO.insertRow(assetReturnRow);
System.out.println("assetReturnInitialization 20");
}
Thx爲提示。第一頁是從2010年的jspx頁面,但我需要弄清楚JSFF頁面片段。第二個似乎不太相關。歡呼聲 –
JSFF仍然有一個綁定層,可以使用InvokeAction。 – Joe
任務流方法不起作用,因爲我需要一些CRUD,爲此我需要迭代器綁定可用。 –