2014-07-01 48 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); 
     } 

}

希望这个作品!