1

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

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

一些代码用于澄清。以下删除点击行的汽车:

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

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

<a4j:commandButton value="Delete" 
                   onclick="#{rich:component('confirmDeletePane')}.show()">
    <a4j:jsFunction name="deleteCar" 
                    action="#{bean.deleteCar(record.carId)}"
                    oncomplete="#{rich:component('confirmDeletePane')}.hide();"
                    render="carsTable"/>
</a4j:commandButton>

<rich:popupPanel id="confirmDeletePane" header="Delete" modal="true" autosized="true" onmaskclick="#{rich:component('confirmDeletePane')}.hide();">
        <h:outputText value="Delete?"/>
        <h:panelGroup>
                <a4j:commandButton value="Cancel" onclick="#{rich:component('confirmDeletePane')}.hide(); return false;" />
                <a4j:commandButton value="OK" onclick="deleteCar(); return false;"/>
        </h:panelGroup>
    </rich:popupPanel>

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

4

1 回答 1

0

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

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
}
于 2012-08-06T09:57:28.690 回答