2017-01-06 37 views
0

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

回答

0

找到了!我需要在Method Call Activity的pageDef中添加迭代器。所以我只需右鍵單擊MCA,然後去pageDef,並將我需要的迭代器添加到可執行列表。

0

您可以將方法添加到後臺bean,然後調用該方法,您導航到頁面的任務流的一部分,或者通過添加調用操作的結合可執行文件。 Thisthis可能會有所幫助。

+0

Thx爲提示。第一頁是從2010年的jspx頁面,但我需要弄清楚JSFF頁面片段。第二個似乎不太相關。歡呼聲 –

+0

JSFF仍然有一個綁定層,可以使用InvokeAction。 – Joe

+0

任務流方法不起作用,因爲我需要一些CRUD,爲此我需要迭代器綁定可用。 –

1

檢查出:輪詢組件。在jsff頁,做這樣的事情:

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

片段時第一次加載時,它調用後臺bean的方法,其中,你現在可以編程方式獲得一個句柄表,找到第一行,並執行所需的操作。輪詢組件還需要調用一些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> 

這是爲了做到這一點,如果你不能在任務流的方法調用,通常是最好做這件事。

+0

像魅力一樣工作謝謝你 –

相關問題