传递<p:selectonelistbox var =“ch”>作为<h:commandlink action =“”> </h:commandlink> </p:selectonelistbox>的参数

时间:2015-01-20 17:12:31

标签: jsf primefaces commandlink selectonelistbox

我遇到了在commandLink中从actionListener传递对象到支持bean的问题。我拥有的是bean MeasureBeanxhtml文件,它使用bean。

在xhtml中我有:

<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>

在bean中我有方法:

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

问题是,无论我是否使用标签<f:ajax>,bean中方法的参数viewCheckpoint始终为null。我需要将该参数传递给bean。它不必是整个对象,只允许传递检查点的id。我也尝试过,是:

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

cp代替ch)。但没有区别。

请帮忙,
Mateusz

1 个答案:

答案 0 :(得分:0)

您忘记设置<p:selectOneListBox>的值。此外,您还必须创建一个转换器。

您可以在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
}