1

我想创建一个按钮来选择所有复选框,但找不到适合我的示例。我正在使用素面。

     <p:selectManyCheckbox widgetVar="sex" id="sexta" value="#{solicitacaoAcompanhamentoMB.selectedHorariosSexta}" layout="pageDirection">  
        <f:selectItem itemLabel="12:00" itemValue="Sexta-12:00" />  
        <f:selectItem itemLabel="12:30" itemValue="Sexta-12:30" /> 
        <f:selectItem itemLabel="13:00" itemValue="Sexta-13:00" /> 
        <f:selectItem itemLabel="13:30" itemValue="Sexta-13:30" /> 
        <f:selectItem itemLabel="14:00" itemValue="Sexta-14:00" />  
        <f:selectItem itemLabel="14:30" itemValue="Sexta-14:30" /> 
        <f:selectItem itemLabel="15:00" itemValue="Sexta-15:00" />  
        <f:selectItem itemLabel="16:00" itemValue="Sexta-16:00" />  
        <f:selectItem itemLabel="16:30" itemValue="Sexta-16:30" />
        <f:selectItem itemLabel="17:00" itemValue="Sexta-17:00" />  
        <f:selectItem itemLabel="17:30" itemValue="Sexta-17:30" /> 
        <f:selectItem itemLabel="18:00" itemValue="Sexta-18:00" />  
        <f:selectItem itemLabel="18:30" itemValue="Sexta-18:30" /> 
        <f:selectItem itemLabel="19:00" itemValue="Sexta-19:00" />  
        <f:selectItem itemLabel="19:30" itemValue="Sexta-19:30" /> 
        <f:selectItem itemLabel="20:00" itemValue="Sexta-20:00" />  
        <f:selectItem itemLabel="20:30" itemValue="Sexta-20:30" /> 
        <f:selectItem itemLabel="21:00" itemValue="Sexta-21:00" />  
        <f:selectItem itemLabel="21:30" itemValue="Sexta-21:30" /> 
        <f:selectItem itemLabel="22:00" itemValue="Sexta-22:00" />  
        <f:selectItem itemLabel="22:30" itemValue="Sexta-22:30" /> 
     </p:selectManyCheckbox>
4

1 回答 1

2

您可以添加 commandLink

<p:commandLink id="selectAll" update="sexta" actionListener="#{yourBean.selectAll}" process="@this,locations">
  <h:outputText value="Select all" />
</p:commandLink>

Java 中的方法(在 yourBean 类中):

public void selectAll(ActionEvent actionEvent) {
    selectedHorariosSexta.clear();
    int startHour = 12;
    for (int i = 0; i < 22; i++) {
        if (i % 2 == 0) {
            selectedHorariosSexta.add("Sexta-" + startHour + ":00");
        }else {
            selectedHorariosSexta.add("Sexta-" + startHour + ":30");
            startHour++;
        }
    }       
}
于 2012-09-07T07:19:30.910 回答