2014-07-01 47 views
0

我使用的是IceFaces的3.3版本,我們有一個人的數據表。我們需要一個擴展按鈕,允許用戶更新數據表中某個人的任何屬性。標籤ace:expansionToggle是我認爲可以使用的標籤,但如果我用changeListener捕獲事件,客戶端已經切換組件。我需要驗證該面板中的所有字段,以便在驗證失敗時,panelExpansion組件不會關閉。這裏有一些代碼來描述我正在嘗試做什麼。將組件綁定到後臺bean似乎是一個好主意,但如果我在expandToggle的getter和setter中設置了斷點,那麼在我可以對其執行任何操作之前,客戶端已經摺疊了該面板。在客戶端切換組件之前是否有方法來攔截ExpansionToggle valueChange事件?

<ace:dataTable id="driverListTable" value="#{persons}" var="person"> 
    <ace:column id="exp"> 
     <ace:expansionToggler 
      binding="#{personBean.expansionToggle}" 
      changeListener="#{directDriverInfoBean.handleToggleEvent}"/> 
    </ace:column> 

    <ace:column headerText="#{msg.label_driver}"> 
     <ice:outputText value="#{person.firstName} #{person.lastName}"/> 
    </ace:column> 

    <ace:column styleClass="dobColWidth" headerText="#{msg.label_dob}"> 
     <ice:outputText value="#{person.userDob}"/> 
    </ace:column> 

    <ace:column styleClass="driverColWidth" headerText="Marital Status"> 
     <ice:outputText value="#{person.maritalStatus}"/> 
    </ace:column> 

    <ace:column headerText="Person Status"> 
     <ice:outputText value="#{person.status}"/> 
    </ace:column> 

    <ace:panelExpansion> 
     <show all fields for person here> 
    </ace:panelExpansion> 
<ace:dataTable> 

我在這裏有什麼選擇?

感謝, 帕特里克

回答

0

我只是發現了關於屬性 'stateMap'。它允許您訪問dataTable中的每一行。 所以你可以做的是,當他們點擊行時,在'handleToggleEvent'方法中,你知道他們點擊了哪行。你可以做你的驗證,如果失敗,您可以檢查您stateMap該行並迫使其進行setExpanded(假)...

//add stateMap attribute to ace:dataTable 

<ace:dataTable id="driverListTable" value="#{persons}" var="person" stateMap="stateMap"> 

//added the attribute currentRow so you can access row object. 

<ace:column id="exp"> 
    <ace:expansionToggler 
     binding="#{personBean.expansionToggle}" 
     changeListener="#{directDriverInfoBean.handleToggleEvent}"> 
     <f:attribute name="currentRow" value="#{person}" /> 
     <ace:expansionToggler> 
    </ace:column> 

//add the following variable to your backing bean 

/** This row state map object allows us access to all the rows in the data table. */ 
    private RowStateMap stateMap = new RowStateMap(); 

// edit your handleToggleEvent() method like the following: 

    public void handleToggleEvent(ExpansionChangeEvent event){ 
     RowObject obj = event.getComponent().getAttributes().get("currentRow");//one way to know what row they clicked. 

     //do your validation 

     if(failed){ 

     /*find the row in the state map.*/ 
     RowState rs = (RowState) stateMap.get(obj); 

     /*force it to not be expanded*/ 
     rs.setExpanded(false); 
     } 

}

希望這個作品!