如何在第一页加载时按页面中 list/table 的第一项?
How to press the first item of a list/table in a page on first page load?
我对 ADF 还很陌生,但仍在积累实践经验。
我只想在用户最初打开 JSFF 页面时调用托管 bean 方法一次。该方法绑定到页面上table 的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();
}
}
编辑:如果我使用方法调用 activity 作为初始 activity,当我尝试访问迭代器的 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");
}
您可以将该方法添加到辅助 bean,然后在导航到页面时作为任务流的一部分调用该方法,或者通过添加 Invoke Action 的绑定可执行文件来调用该方法。 This or this 可能会有帮助。
检查 af:poll 组件。在 jsff 页面中,执行如下操作:
<af:poll id="p1" interval="10" pollListener="#{pageFlowScope.wci.handleFragmentLoad}">
<af:clientListener method="resetPollInterval" type="poll"/>
</af:poll>
当片段首次加载时,它会调用支持 bean 方法,您现在可以在该方法中以编程方式获取 table 的句柄、查找第一行并执行所需的操作。轮询组件还需要调用一些 javascript (clientListener) 来关闭轮询,一旦它在页面加载时运行。这看起来像:
<af:resource type="javascript">
function resetPollInterval(e) {
var src = e.getSource();
var poll = src.findComponent("p1");
if (poll != null) {
poll.setInterval( -1);
}
}
</af:resource>
如果您无法通过任务流中的方法调用执行此操作,这是一种方法,通常更可取。
找到了!我需要在方法调用 Activity 的 pageDef 中添加迭代器。所以我只需要右键单击 MCA,然后转到 pageDef 并将我需要的迭代器添加到可执行文件列表中。
我对 ADF 还很陌生,但仍在积累实践经验。
我只想在用户最初打开 JSFF 页面时调用托管 bean 方法一次。该方法绑定到页面上table 的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();
}
}
编辑:如果我使用方法调用 activity 作为初始 activity,当我尝试访问迭代器的 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");
}
您可以将该方法添加到辅助 bean,然后在导航到页面时作为任务流的一部分调用该方法,或者通过添加 Invoke Action 的绑定可执行文件来调用该方法。 This or this 可能会有帮助。
检查 af:poll 组件。在 jsff 页面中,执行如下操作:
<af:poll id="p1" interval="10" pollListener="#{pageFlowScope.wci.handleFragmentLoad}">
<af:clientListener method="resetPollInterval" type="poll"/>
</af:poll>
当片段首次加载时,它会调用支持 bean 方法,您现在可以在该方法中以编程方式获取 table 的句柄、查找第一行并执行所需的操作。轮询组件还需要调用一些 javascript (clientListener) 来关闭轮询,一旦它在页面加载时运行。这看起来像:
<af:resource type="javascript">
function resetPollInterval(e) {
var src = e.getSource();
var poll = src.findComponent("p1");
if (poll != null) {
poll.setInterval( -1);
}
}
</af:resource>
如果您无法通过任务流中的方法调用执行此操作,这是一种方法,通常更可取。
找到了!我需要在方法调用 Activity 的 pageDef 中添加迭代器。所以我只需要右键单击 MCA,然后转到 pageDef 并将我需要的迭代器添加到可执行文件列表中。