1

我有一个丰富的:数据表,其中有很多列,其中一列是 h:selectbooleancheckbox。我希望用户一次只从数据表中的许多复选框中选择一个复选框。如果一个复选框被选中一次,我没有问题我可以将它提交到表单。When a second checkbox is selected, for example, the former one should be deselected. 我怎么能这样做?提前感谢您的帮助......这是我正在使用的数据表:

<rich:dataTable id="vehicleTable" var="vhcl" value="#{tripsBacking.vehicleList}"
binding="#{tripsBacking.vehicleTable}" sortMode="single" 
footerClass="dr-table-footer rich-table-footer"
style="width: 500px; margin: 0px; padding: 0px;">

<rich:column id="col1" width="10px" headerClass="dr-table-header rich-table-header">
    <f:facet name="header">

    </f:facet>
    <h:selectBooleanCheckbox title="#{general.select}" >
    </h:selectBooleanCheckbox>
</rich:column>
<rich:column id="col2" label="#{general.vehicleName}" headerClass="dr-table-header rich-table-header" >
    <f:facet name="header">
        <h:outputText value="#{general.vehicleName}" id="vehicleNameLbl" />
    </f:facet>
    <h:outputText value="#{vhcl.vehicle.vehicleName}" id="vehicleNameValue" />
</rich:column>

<rich:column id="col3" label="#{general.vehicleType}" headerClass="dr-table-header rich-table-header" >
    <f:facet name="header">
        <h:outputText value="#{general.vehicleType}"
            id="state_capital" />
    </f:facet>
    <h:graphicImage value="#{vhcl.typeImage}" height="40" width="40" align="left"/>
</rich:column>
<rich:column id="col4" label="#{general.lastMessageDate}"
    headerClass="dr-table-header rich-table-header" > 
    <f:facet name="header">
        <h:outputText value="#{general.lastMessageDate}" id="lastMsgDateLabel" />
    </f:facet>
    <h:outputText value="#{vhcl.messageDate}" id="lastMsgDate" /> 
</rich:column>
<rich:column id="col5a" label="#{general.address}"
    headerClass="dr-table-header rich-table-header" >
    <f:facet name="header">
        <h:outputText value="#{general.address}" id="addressLabel" />
    </f:facet>
    <h:outputText value="#{vhcl.address}" id="addr" />
</rich:column>

4

1 回答 1

0

Ajax 提交每次更改并有一个动作侦听器方法,该方法将从列表中取消选择所有先前选择的项目。

<h:selectBooleanCheckbox title="#{general.select}" >
    <a4j:support event="onclick" listener="#{tripsBacking.selectSingleRow}" reRender="vehicleTable">
       <!-- use property that uniquely identifies a row -->
       <f:attribute name="selectedVehicleName" value="#{general.vehicleName}"/>
    </a4j:support>
</h:selectBooleanCheckbox>

它将类似于上面的内容,其中 deselectAll 是 bean 中的一个动作侦听器方法:

public void selectSingleRow(ActionEvent event) {
    String vehicleName = (String) event.getComponent().getAttributes().get("selectedVehicleName");
    for (Vehicle v : vehicleList) {
          if (!v.getVehicleName.equals(vehicleName)) {
               v.setSelected(false);     
          }
    } 
}
于 2013-01-16T12:18:03.280 回答