Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 RichFaces数据表行删除_Jsf 2_Richfaces - Fatal编程技术网

Jsf 2 RichFaces数据表行删除

Jsf 2 RichFaces数据表行删除,jsf-2,richfaces,Jsf 2,Richfaces,我在中有一列,其中包含用于删除行的 通过commandButton的操作属性调用bean的delete函数(例如{bean.deleteCar(record.carId)})时,删除行可以正常工作。不幸的是,当使用的操作属性时,最后一行的记录.carId将传递给bean,而不是所选行 一些代码需要澄清。以下操作将删除单击行的车辆: <a4j:commandButton value="Delete" action="#{bean.deleteCar(re

我在
中有一列,其中包含用于删除行的

通过commandButton的
操作
属性调用bean的delete函数(例如
{bean.deleteCar(record.carId)}
)时,删除行可以正常工作。不幸的是,当使用
操作
属性时,最后一行的
记录.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>

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

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

commandLink(调用confirmPane):


a4j:jsFunction不应该嵌套在commandButton中。您应该在模式中传递该值,然后在确认按钮上将action属性中的值传递给backing bean,该bean是汽车的id。@Ellie感谢您的评论。我尝试了类似的方法:通过使用将值直接传递给支持bean。如果您有任何将值传递给模式(例如索引)的示例代码,请随意分享。我将尝试创建与您相同的示例,然后我将在此处发布代码。:)
<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>
<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>
<a4j:jsFunction name="remove" action="#{carsBean.remove}" render="table" execute="@this"
        oncomplete="#{rich:component('confirmPane')}.hide();" />
private int currentCarIndex; // with the getter/setter

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