如何在第一页加载的页面中按下列表/表格的第一项?

时间:2017-01-06 13:00:01

标签: oracle-adf

我对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");
    }

3 个答案:

答案 0 :(得分:1)

查看af:民意调查组件。在jsff页面中,执行以下操作:

<af:poll id="p1" interval="10" pollListener="#{pageFlowScope.wci.handleFragmentLoad}">
                    <af:clientListener method="resetPollInterval" type="poll"/>
</af:poll>

当片段首次加载时,它会调用backing bean方法,在该方法中,您现在可以以编程方式获取表的句柄,查找第一行并执行所需的操作。 poll组件还需要调用一些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>

如果您不能通过任务流中的方法调用来执行此操作,这是一种方法,这通常是可取的。

答案 1 :(得分:0)

您可以将该方法添加到辅助bean,然后在作为任务流的一部分导航到页面时调用该方法,或者通过添加Invoke Action的绑定可执行文件来调用该方法。 Thisthis可能有所帮助。

答案 2 :(得分:0)

发现它!我需要在Method Call Activity的pageDef中添加迭代器。所以我只需右键单击MCA然后转到pageDef并将我需要的迭代器添加到可执行列表中。