0

I'm facing problem with passing object to backing bean from actionListener in commandLink. What I have, is a bean MeasureBean and a xhtml file, that uses the bean.

In the xhtml I have:

<p:selectOneListbox var="ch">
    <f:selectItems value="#{MeasureBean.checkpoints}" var="cp" itemValue="#{cp}" />
    <p:column>
        <h:outputText value="#{ch.name}" />
    </p:column>
    <p:column>
        <h:commandLink actionListener="#{MeasureBean.onCheckpointRemoved(ch)}">
            <h:graphicImage library="#{ctx.theme}" name="images/delete.gif" />
            <f:ajax event="click" />
        </h:commandLink>
    </p:column>
</p:selectOneListbox>

In the bean I have method:

public void onCheckpointRemoved(Checkpoint viewCheckpoint) {
    System.out.println(viewCheckpoint);
    // TODO
}

The problem is, that regardless of whethert I use the tag <f:ajax> or not, the parameter viewCheckpoint of the method in bean is always null. I need to pass that parameter to the bean. It doesn't have to be the whole object, it is allowed to pass just the id of the checkpoint. What I also tried, was:

<h:commandLink actionListener="#{MeasureBean.onCheckpointRemoved(cp)}">

(cp instead of ch). But no difference.

Please help,
Mateusz

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Mateusz Moroz
  • 312
  • 2
  • 6
  • 19

1 Answers1

0

You forgot to set the value of <p:selectOneListBox>. Also, you'll have to create a converter.

You can check an example of converter in PrimeFaces Showcase

<p:selectOneListbox var="ch" value="#{MeasureBean.checkPointTest}" converter="checkPointConverter">
<f:selectItems value="#{MeasureBean.checkpoints}" var="cp" itemValue="#{cp}" />
<p:column>
    <h:outputText value="#{ch.name}" />
</p:column>
<p:column>
    <h:commandLink actionListener="#{MeasureBean.onCheckpointRemoved(ch)}">
        <h:graphicImage library="#{ctx.theme}" name="images/delete.gif" />
        <f:ajax event="click" />
    </h:commandLink>
</p:column>
</p:selectOneListbox>

Checkpoint checkPointTest;
// getter/setter....
public void onCheckpointRemoved(Checkpoint viewCheckpoint) {
System.out.println(viewCheckpoint);
// TODO
}
Pellizon
  • 1,365
  • 2
  • 12
  • 26
  • Thanks Pellizon. I tried your proposal, but now the listbox it doesn't render its content at all. No items in the box. I think, that the `` tag is needed in the definition of listbox. – Mateusz Moroz Jan 21 '15 at 09:16
  • Check the answer again! Now it's a little more accurate shot :) – Pellizon Jan 21 '15 at 09:46
  • Thanks! That's the same way, that I did it, isn't it? The only difference is value and the presence of converter... Edit: I managed to solve the problem with a JS "hack". I added the ``, to which I set the value with JS on click event and then I call the method of the bean. `` Now it works like a charm – Mateusz Moroz Jan 22 '15 at 10:56