JSF f:selectItem in h:selectManyCheckbox not working in backing bean, but is displayed properly in h:dataTable

jsflifecycleselectmanycheckboxvaluechangelistener

The problem occurs with this code:

<h:form>
    <rich:panel>
        <f:facet name="header">
            <h:selectManyCheckbox title="Select which types of requests you want to see"
                                  onchange="submit();" value="#{filterListener.chosenFilters}"
                                  id="selectBoxContainer" >
                <f:selectItem id="approvedByITS" itemLabel="Approved by ITS" itemValue="approvedByITS"  />
                <f:selectItem id="approvedByPO" itemLabel="Approved by Process Owner" itemValue="approvedByPO"   />
                <f:selectItem id="dob" itemLabel="Date" itemValue="dob"   />
                <f:selectItem id="externalAssignedTo" itemLabel="External assigned" itemValue="externalAssignedTo"  />
                <f:selectItem id="internalAssignedTo" itemLabel="Internal assigned" itemValue="internalAssignedTo"   />
                <f:selectItem id="ITSapprovedBy" itemLabel="ITS approved by" itemValue="ITSapprovedBy"  />
                <f:selectItem id="severity" itemLabel="Severity" itemValue="severity"  />
                <f:selectItem id="status" itemLabel="status" itemValue="status" />
                <f:valueChangeListener type="no.ngt.tech.rt2.listeners.requestFilterListener" />
            </h:selectManyCheckbox>
        </f:facet>

        <h:dataTable value="#{filterListener.chosenFilters}" var="selects" >
            <h:column>
                <h:outputText value="#{selects}" />
            </h:column>
        </h:dataTable>
        <br />
        <h:messages />

    </rich:panel>
</h:form>

As we can see I have the value="#{filterListener.chosenFilters}". The dataTable's value is also the same, so whenever I click one of the selectItem's the dataTable has an element added or removed from it (this is working). In my backing bean I have the following code:

public class requestFilterListener implements ValueChangeListener {

    private List<String> chosenFilters;

    public requestFilterListener() {
    }

    public void processValueChange(ValueChangeEvent event) {
        System.out.println("processValueChange called");
        if (chosenFilters != null) {
            System.out.println(chosenFilters.size());
        }
    }

    public List<String> getChosenFilters() {
        return chosenFilters;
    }

    public void setChosenFilters(List<String> chosenFilters) {
        this.chosenFilters = chosenFilters;
    }

Everytime I click one of the checkboxes, a column is added/removed with the proper data, in my console I get the message "processValueChange called" as I output in the processValueChange method, but during this time chosenFilters is always null, and the if expression is never run. How come? This is a session bean, and I really dont understand why my list cant be used within the backing bean, but is used without a problem by my dataTable.

Thanks for your time in looking into this.

Best Solution

The problem is probably on this tag:

<f:valueChangeListener type="no.ngt.tech.rt2.listeners.requestFilterListener" />

You are instructing the f:valueChangeListener tag to create a new instance of requestFilterListener instead of binding to the one specified by the managed bean configuration. Use the binding attribute to bind to #{filterListener}.