【问题标题】:Pass <p:selectOneListbox var="ch"> as argument of <h:commandLink action>传递 <p:selectOneListbox var="ch"> 作为 <h:commandLink action> 的参数
【发布时间】:2015-01-20 17:12:31
【问题描述】:

我在将对象从 commandLink 中的 actionListener 传递给支持 bean 时遇到问题。我拥有的是一个使用 bean 的 bean MeasureBean 和一个 xhtml 文件。

在我的 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
}

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

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

cp 而不是ch)。但没有区别。

请帮忙,
马特乌斯

【问题讨论】:

    标签: jsf primefaces commandlink selectonelistbox


    【解决方案1】:

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

    您可以在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。我尝试了您的建议,但现在列表框根本不呈现其内容。盒子里没有物品。我认为,列表框的定义中需要&lt;f:selectItems&gt; 标签。
    • 再次检查答案!现在它是一个更准确的镜头:)
    • 谢谢!我也是这样做的,不是吗?唯一的区别是价值和转换器的存在......编辑:我设法用JS“hack”解决了这个问题。我添加了&lt;h:inputHidden&gt;,我在点击事件上用JS设置了值,然后我调用了bean的方法。 &lt;f:ajax event="click" listener="#{MeasureBean.foo()}" execute="editForm:checkpoint_id_to_rmeove" render="editForm:editor_line" /&gt; 现在它就像一个魅力
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-07
    • 2011-03-30
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    相关资源
    最近更新 更多