I have the following problem: I am using a h:selectManyChecbox
inside a ui:repeat
. A value change listener is attached to the component, as well as a f:ajax
. I want the event to be triggered on each selection/deselection, then manipulate some values in the backing bean and update the view accordingly. I reduced it to the following example:
JSF Page
<ui:repeat id="loop" value="#{testAction.stringListe}" var="string">
<h2>#{string}</h2>
<h:inputText id="input" value="#{testAction.testInt}" />
<h:selectBooleanCheckbox value="#{testAction.testBoolean}"
id="checkbox"
valueChangeListener="#{testAction.valueChangeListener}">
<f:ajax render="input" />
</h:selectBooleanCheckbox>
<h:outputLabel for="checkbox" value="Change Me!"/>
<h:selectManyCheckbox id="options"
value="#{testAction.selections}"
layout="pageDirection"
valueChangeListener="#{testAction.valueChangeListener}">
<f:ajax render="input" />
<f:selectItem itemValue="changeMe" itemLabel="Change me!" />
<f:selectItem itemValue="changeToo" itemLabel="Me too!" />
</h:selectManyCheckbox>
</ui:repeat>
Backing Bean
public class TestAction {
private boolean testBoolean;
private int testInt;
List<String> stringListe = new ArrayList<String>();
List<String> selections = new ArrayList<String>("Number 1", "Number 2");
// Getter + Setter accordingly
public void valueChangeListener(ValueChangeEvent event) {
testInt = (int) (Math.random() * 100);
System.out.println(testInt);
}
For this setup I get the following error:
<f:ajax> contains an unknown id 'form:loop:0:options' - cannot locate it in the context of the component options
So it seems, the render target is not a problem here. Instead, the implicit @this of the ajax`s execute seems to fail. In other words: the component can't find itself. Weirdly enough, this only applies to the selectManyCheckbox. The single checkbox is fine. I am assuming this is due to the fact that the selectMany kind of serves as an "inner loop", so we have two nested loops here. This sounds oddly familiar to what I asked in this question, only there it was the render target causing the problem.
So my question is: Is this expected behaviour? Or is it some known bug in the implementation? I'm asking because selectManyListBox and selectManyMenu work just fine... In any case I am looking for a way to work around this. Has anybody else a similar problem?
Notes: Unfortunately, c:foreach is no option, or else I'd have tried ;) Fiddling with the execute parameter did not have an effect (e.g execute=@form).
Edit : This works when using p:ajax
from Primefaces. I'll leave this open for a while anyways in case there are some other useful answers. If anybody knows what the p:ajax does differently, this would also be interesting to know.