取消选择单个复选框时,Primefaces selectCheckboxMenu行为不稳定 [英] Primefaces selectCheckboxMenu erratic behavior when deselecting individual checkboxes

查看:167
本文介绍了取消选择单个复选框时,Primefaces selectCheckboxMenu行为不稳定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基于jsf 2.1和Primefaces 6.1.5的应用程序中,我很难实现<p:selectCheckboxMenu

In an application based on jsf 2.1 and Primefaces 6.1.5, I have difficulties implementing a <p:selectCheckboxMenu

我根据此处的说明简化了代码如何创建最小,完整和可验证的示例 现在,我的代码看起来与Primefaces Showcase中的代码非常相似. Primefaces Showcase

I simplified the code according to the instructions here How to create a Minimal, Complete, and Verifiable example My code now looks quite similar to the code in the Primefaces Showcase. Primefaces Showcase

经过大量分析,我可以更好地描述不稳定".取消选择项目时,其后的项目会受到影响.最后一项完全不受影响.并且第一项永远都不会被取消选择.似乎是使用索引的错误.

After much analyzing, I can describe 'erratic' a bit better. When deselecting an item, the item following it is affected. The last item is not affected at all. And the first item can never be deselected. It seems like a bug in the use of indices.

任何人都可以确认这一点并提出解决方法吗?

Can anyone confirm this and perhaps suggest a Workaround?

这是xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui">

    <h:form id="form">
        <p:panel>
            <p:selectCheckboxMenu id="testSCM"
                                  value="#{myForm.testList}"
                                  multiple="true"
                                  label="Choose item..."
                                  updateLabel="true">
                <f:selectItems var="s"  value="#{myForm.testItems}" itemLabel="#{s}" />
            </p:selectCheckboxMenu>
        </p:panel>

        <p:commandButton value="Submit" update="displayItems" oncomplete="PF('itemDialog').show()" style="margin-top:10px;" />

        <p:dialog header="Selected Items" modal="true" showEffect="fade" hideEffect="fade" widgetVar="itemDialog" width="250">
            <p:outputPanel id="displayItems">
                <p:dataList value="#{myForm.statusList}" var="item" emptyMessage="No items selected">
                    <f:facet name="header">
                        Status
                    </f:facet>
                    #{item}
                </p:dataList>
            </p:outputPanel>
        </p:dialog>
    </h:form>
</ui:composition>

这是表格:

@Named("myForm")
@SessionScoped
public class MyForm implements Serializable {

    private String[] testList;
    private List<String> testItems;

    public String[] getTestList() {
        return testList;
    }

    public void setTestList(String[] testList) {
        this.testList = testList;
    }

    public List<String> getTestItems() {
        return testItems;
    }

    public void setTestItems(List<String> testItems) {
        this.testItems = testItems;
    }

    public void reset() {
        testItems = new ArrayList<>();
        testItems.add("Item1");
        testItems.add("Item2");
        testItems.add("Item3");
        testItems.add("Item4");
        testItems.add("Item5");
        testItems.add("Item6");
    }
}

推荐答案

该问题是由Primefaces 6.1.5版中的错误引起的.当我降级到6.0版或升级到6.1.8版时,代码可以正常工作.

The problem was caused by a bug in Primefaces version 6.1.5. The code works fine when downgrading to Version 6.0 or upgrading to Version 6.1.8, which is what I chose to do.

该问题在 github上的Primefaces问题跟踪器中进行了描述

这篇关于取消选择单个复选框时,Primefaces selectCheckboxMenu行为不稳定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆