Primefaces selectCheckboxMenu erratic behavior when deselecting individual checkboxes

耗尽温柔 提交于 2019-12-12 04:43:56

问题


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

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?

Here is the 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>

And this is the form:

@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");
    }
}

回答1:


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.

The problem is described in Primefaces issue tracker on github



来源:https://stackoverflow.com/questions/47054616/primefaces-selectcheckboxmenu-erratic-behavior-when-deselecting-individual-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!