Question

my value attribute in my selectManyCheckbox gets overriden wehn updating via ajax. Here is my jsf (1.2)

<h:selectManyCheckbox 
    id="SelectManyCheckbox"
    valueChangeListener="#{parameter.valueChanged}"
    value="#{parameter.selectedValues}">

    <a4j:support 
        event="onclick"
        reRender="selectionPanel" />

    <f:selectItems
        value="#{parameter.values}" />

</h:selectManyCheckbox>

This is the Parameter class (simplified):

public class Parameter {

    List<String> selectedValues;
    SelectItemList values;

    public void valueChanged(ValueChangeEvent event) {
        // here new values and new selectedValues will be set via
        // the setters of the two fields
    }

}

The Problem is, that the new values will be set and displayed correctly, but the selectedValues will stay on the value before the ajax event. I debugged it and i can see that the selectedValues get set correctly but the old selectedValues from before the ajax event will be set during the rerender of the selectionPanel.

When I trigger the event multiple times i can see, that my selectedValues are always overwritten by the value before, like this:

  • init. selectedValue: (0)
  • Event1 newSelectedValue: (1,2,3,4), actually displayed selectedValue(0)
  • Event2 newSelectedValue: (5,6,7,8), actually displayed selectedValue(1,2,3,4)
  • Event3 newSelectedValue: (9,10,11,12), actually displayed selectedValue(5,6,7,8)
  • [...]

Here a part of the stacktrace that overwrites the selectedValue:

com.my.package.structure.Parameter:setSelectedValues
sun.reflect.NativeMethodAccessorImpl:invoke0
sun.reflect.NativeMethodAccessorImpl:invoke
sun.reflect.DelegatingMethodAccessorImpl:invoke
java.lang.reflect.Method:invoke
javax.el.BeanELResolver:setValue
javax.el.CompositeELResolver:setValue
org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver:setValue
org.apache.el.parser.AstValue:setValue
org.apache.el.ValueExpressionImpl:setValue
com.sun.facelets.el.TagValueExpression:setValue
javax.faces.component.UIInput:updateModel
javax.faces.component.UIInput:processUpdates
Was it helpful?

Solution

The solution was to use a simple Array rather than a List.

public class Parameter {

    String[] selectedValues; //CHANGED
    SelectItemList values;

    public void valueChanged(ValueChangeEvent event) {
        // here new values and new selectedValues will be set via
        // the setters of the two fields
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top