【问题标题】:How to implement "Select all" on selectManyCheckbox如何在 selectManyCheckbox 上实现“全选”
【发布时间】:2016-04-20 21:27:36
【问题描述】:

我想设置 selectManyCheckbox 的复选框来检查条件是否为真 "#{myBean.isCondition}":

MyBean.java

public class MyBean{
  private boolean isCondition;
  ...

  public boolean isCondition{
      return isCondition;
  }
  ...
}

my_page.jspx:

<h:selectManyCheckbox 
    layout="pageDirection"
    label="#{messages['numsTelephone.label']}"
    value="#{listSelected}">
    <s:selectItems var="clientTelephone" 
                value="#{list}"
                label="#{clientTelephone}" />
</h:selectManyCheckbox>

我需要知道它是否存在类似

checked = "#{myBean.isCondition}"

我可以在我的 selectManyCheckbox 块中添加吗?或者我应该使用 javascript 吗?

也欢迎任何其他解决方案。

我的另一个问题是如果选中复选框,如何将 myBean.isCondition 设置为 true ?

谢谢,

【问题讨论】:

    标签: jsf selectall selectmanycheckbox selectbooleancheckbox


    【解决方案1】:

    在“全选”复选框中使用&lt;f:ajax&gt;,并在侦听器方法中进行选择工作,然后重新渲染复选框。

    启动示例:

    <h:form>
        <h:selectBooleanCheckbox value="#{bean.selectAll}">
            <f:ajax listener="#{bean.onSelectAll}" render="items" />
        </h:selectBooleanCheckbox>
        <h:selectManyCheckbox id="items" value="#{bean.selectedItems}">
            <f:selectItems value="#{bean.availableItems}" />
        </h:selectManyCheckbox>
    </h:form>
    

    @Named
    @ViewScoped
    public class Bean implements Serializable {
    
        private boolean selectAll; // +getter +setter
        private List<String> selectedItems; // +getter +setter
        private Map<String, String> availableItems; // +getter (no setter necessary)
    
        @PostConstruct
        public void init() {
            availableItems = new LinkedHashMap<String, String>();
            availableItems.put("Foo label", "foo");
            availableItems.put("Bar label", "bar");
            availableItems.put("Baz label", "baz");
        }
    
        public void onSelectAll() {
            selectedItems = selectAll ? new ArrayList<>(availableItems.values()) : null;
        }
    
        // ...
    }
    

    【讨论】:

      猜你喜欢
      • 2017-12-30
      • 2014-03-26
      • 1970-01-01
      • 1970-01-01
      • 2015-03-28
      • 1970-01-01
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多