【问题标题】:Call listener by clicking pencil (primefaces 2.2.1 rowEditor)通过单击铅笔调用监听器(primefaces 2.2.1 rowEditor)
【发布时间】:2012-08-09 16:10:03
【问题描述】:

在 rowEditor 上单击铅笔后如何调用侦听器? 我想从 dataTable 准备文本进行编辑(清除标签和回车的 html 标签)。 你有什么想法? 谢谢。

【问题讨论】:

  • 有一个名为“rowEdit”的 ajax 事件,但我不确定它是否在您单击铅笔或完成编辑行时执行。你试过了吗?
  • 当有人完成编辑时调用 RowEditEvent。你有什么想法,我如何修改单元格数据进行编辑?谢谢。
  • 在 xhtml 中: 在 bean 中,public void handleRowEdit(RowEditEvent re)

标签: java html jsf-2 primefaces


【解决方案1】:

实际上,数据表中没有铅笔事件。如果你想在铅笔点击后调用监听器,你可以这样做。将rowEditor包装到commandLink中。我做到了,它可以工作。

<p:commandLink id="rowEditLink" action="#{teamMB.initCombo}" ajax="true"
                        update=":formContent:teamTable>

      <p:rowEditor />
 </p:commandLink >

【讨论】:

    【解决方案2】:

    这不适用于 2.2.1 版本,但它仍然适用于其他版本

    2 年前的问题,但它是 Google 的热门搜索结果之一。

    有一种方法可以在不使用&lt;p:commandLink&gt;的情况下做到这一点

    第 154 页上的 Primefaces User Guide 谈到了 ajax 事件。有三个感兴趣的事件rowEdit, rowEditInit, rowEditCancel

    rowEditInit 是当行切换到编辑模式时触发的事件 rowEditCancel 是取消行编辑时触发的事件

    所以你的代码应该是这样的

    <p:ajax event="rowEditInit" listener="#{tableBean.onEditInitCleanUp}" update="@form">
    

    然后你的听众会做适当的清理。

    【讨论】:

    • 您应该注意到问题中的 primefaces 版本!
    • 可能你不需要 'update' 参数,因为 会更新行。在我的情况下,表格在一个对话框中,所以如果你更新它会关闭,在这种情况下,你必须负责重新打开对话框。 PS:ajax方案相当优雅
    猜你喜欢
    • 2013-04-03
    • 1970-01-01
    • 2014-05-08
    • 2023-03-15
    • 2012-12-16
    • 2012-12-27
    • 1970-01-01
    • 2020-06-16
    • 2014-09-09
    相关资源
    最近更新 更多