RichFaces dataTable行删除

时间:2012-07-30 14:32:57

标签: jsf-2 richfaces

我在<rich:dataTable>中有一个包含<a4j:commandButton>的列,用于删除行。

通过commandButton的#{bean.deleteCar(record.carId)}属性调用bean的删除函数(例如action)时,删除行可以正常工作。不幸的是,当使用<a4j:jsFunction>的{​​{1}}属性时,最后一行的action将传递给bean,而不是选定的行。

一些代码需要澄清。以下内容删除所点击行的汽车:

record.carId

以下内容删除了最后一行的汽车:

<a4j:commandButton value="Delete"
                   action="#{bean.deleteCar(record.carId)}"/>

正如您所看到的,我正在尝试在删除之前确认用户的选择。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

正如showcase建议的那样,我得出结论,一个改进的解决方案是使用索引进行行选择。我在这里复制以供将来参考。

commandLink(调用confirmPane):

<a4j:commandLink execute="@this"
                 render="@none"
                 oncomplete="#{rich:component('confirmPane')}.show()">
       <h:graphicImage value="/images/icons/delete.gif" alt="delete" />
       <a4j:param value="#{it.index}" assignTo="#{carsBean.currentCarIndex}" />
</a4j:commandLink>

confirmPane(调用JS函数):

<rich:popupPanel id="confirmPane" autosized="true">
        Delete?
        <a4j:commandButton value="Cancel" onclick="#{rich:component('confirmPane')}.hide(); return false;" />
        <a4j:commandButton value="Delete" onclick="remove(); return false;" />
</rich:popupPanel>

jsFunction(调用Bean的函数):

<a4j:jsFunction name="remove" action="#{carsBean.remove}" render="table" execute="@this"
        oncomplete="#{rich:component('confirmPane')}.hide();" />

在支持bean中:

private int currentCarIndex; // with the getter/setter

public void remove() {
    // do your List removal (or DB transaction)
    // with the currentCarIndex
}