【问题标题】:Error Primefaces p:commandLink错误 Primefaces p:commandLink
【发布时间】:2014-03-13 07:02:32
【问题描述】:

您好,我正在使用 JSF 和 PrimeFaces 3.5 2.1.17,我的代码如下:

<p:dataTable id="resultTable" var="entity" value="#{requerimentoBean.entitys}" >
    <p:column style="width: 22px;">
        <p:commandLink actionListener="#{requerimentoBean.prepareEdition(entity)}">
            <h:graphicImage library="images" title="Editar" name="edit.png" style="border: none;" />
        </p:commandLink>
    </p:column>
</p:dataTable>

问题出现在这一行:

<p:commandLink actionListener="#{requerimentoBean.prepareEdition(entity)}">

放置实体参数时发生错误。方法不能prepareEdition是accessor。

public void prepareEdition(Requerimento entity){
    System.out.println("***** Método preperaEdition ****");
    System.out.println("***** ID: " + entity.getId() + "*****");
    setEntity(logic.getById(entity.getId()));
}

如果你能帮忙谢谢

【问题讨论】:

  • 将 actionListener 替换为 之类的操作。你的 actionListener 绑定方法应该有一个签名,比如 public void method(ActionEvent event)
  • 有访问方法 public void prepareEdition(ActionEvent 事件),我使用的是 2.1.17 JSF 2.5 和 PrimeFaces 会出现版本问题吗?导入:导入 javax.faces.event.ActionEvent;
  • 您不能将实体对象作为参数传递。按照我说的替换。我没明白你到底想说什么。你能详细说明一下吗?
  • Eu estoutentando editar um registro passando o id dele por parametro, algo assim: tudo isso dentro de um ... Mas eu nao consigo entrar no metido public void edition(ActionEvent event)... obrigada

标签: jsf-2 primefaces commandlink


【解决方案1】:

这是传递对象的方式

<p:commandLink
    actionListener="#{requerimentoBean.prepareEdition()}">
    <h:graphicImage library="images" title="Editar" name="edit.png"
        style="border: none;" />
    <f:setPropertyActionListener target="#{requerimentoBean.entityObj}"
        value="#{entity}" />
</p:commandLink>

【讨论】:

    【解决方案2】:

    将 actionListener 替换为类似

    的动作
     <p:commandLink process="@this"  
                    action="#{requerimentoBean.prepareEdition(entity)}">.   
    

    你的actionListener绑定方法应该有一个像

    这样的签名
      public void method(ActionEvent event)  
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-08-09
      • 1970-01-01
      • 2012-05-15
      • 2019-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多