2

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.

Community
  • 1
  • 1
Louise
  • 1,451
  • 1
  • 18
  • 40
  • 1
    Taking notice of your functional requirement, I'm wondering why are you using `h:selectManyChecbox` inside of a `ui:repeat` instead using only one `h:selectManyChecbox` and manipulating it's CSS and backend. – Ömer Faruk Almalı Apr 12 '13 at 12:13
  • The page dislays data for multiple entries (people, in this case), which come from a list, hence the ui:repeat. The checkboxes are there to create a mapping between people and things they possibly own. I need to collect the data for each person individually, hence the checkboxes inside the repeat. I don't quite see how this would be solved with "CSS and backend", whatever "backend" encompasses ;) – Louise Apr 15 '13 at 14:40
  • Assume that you got only one selectManyCheckbox and 50 checkboxes, 5 people, 10 for each. And construct an algorithm which allocates boxes to specific person for example 1-10 person1, 10-20 person2 etc. So if you can manipulate CSS of boxes issue will be solved. If you want to implement it this way I can help you about CSS and post it as an answer? – Ömer Faruk Almalı Apr 15 '13 at 14:50

0 Answers0