0

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");
    }
}
Robert
  • 478
  • 6
  • 19
  • 1
    So it works if you use a 'simple' list that does not need a converter? – Kukeltje Nov 01 '17 at 16:53
  • Good idea to test this with a simple list. I get the same behavior. It is clear now, that the problem is not related to the converter. – Robert Nov 02 '17 at 16:11
  • 1
    These things are steps in creating a [mcve]. Always good to do that. Helps localizing the problem and creating better /clearer questions. Is the styleClass attribute relevant? The panelStyleClass? If not remove them to (as you should the converter). Add a simple bean too for the problem to be more easily verifyable – Kukeltje Nov 02 '17 at 16:15
  • They are not relevant and I removed all per your suggestion. There seems to be a bug in Primefaces concerning the indices used. In a test with 3 Strings, selecting/deselecting the first is not possible. Same with the last (third) item. The label is displayed incorrectly. However, the checkboxes appear as they should. – Robert Nov 02 '17 at 16:33
  • The converter is still there – Kukeltje Nov 02 '17 at 16:47
  • In a further test with the simplified xhtml code and the added `multiple="true"`attribute, everything works as expected. I suppose I could proceed with that. However, I'm expecting to have a very hard time recreating the original style and layout. For example, I don't get the label to be displayed at all, unless some checkboxes have already been checked. – Robert Nov 02 '17 at 17:29
  • I was wrong in my comment above - it does not work, it just looks correct in the frontend. There seems to be a bug related to the array index. Quite consistently, a click on the first item affects the 2nd value. And clicks on the last value does not have any effect. – Robert Nov 03 '17 at 16:54
  • then there is one thing to do... [mcve] – Kukeltje Nov 03 '17 at 18:07
  • Thanks for your patience, Kukultje, I now revised my question to the guid: 'How to create a Minimal, Complete, and Verifiable example'. Very useful and sensible indeed! – Robert Nov 05 '17 at 17:53

1 Answers1

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

Robert
  • 478
  • 6
  • 19