Primefaces 5使用确认框删除数据网格内的按钮单击确认框的是,将参数值传递给bean

时间:2014-07-10 10:32:49

标签: primefaces

我们正在使用Primefaces 5

我们为搜索结果提供了一个数据网格。在datagrid内部,每行都有一个删除按钮。点击删除按钮,当用户点击确认对话框的是按钮时,会显示一个确认框,然后调用bean的deleteUser方法,并删除参数id为'testUserId'的用户。问题是发送给bean的'testUserId'的值始终是datagrid最后一行的userId的值。如何传递' testUserId'的价值?从删除按钮单击到bean方法的当前行? 以下是代码的片段

XHTML:可 -

                    <p:commandButton action="#{bean.deleteUser}" value="Delete"

                                            ajax="false" onclick="PF('confirmation').show()" type="button">

                    </p:commandButton>



                    <p:confirmDialog

                                message="Are you sure about deleting the user?"

                                header="Initiating user deletion" severity="alert"

                                widgetVar="confirmation" appendTo="">

                                <p:commandButton value="Yes Sure" ajax="false" onclick="resetSearchForm()"

                                            oncomplete="PF('confirmation').hide()" action="#{bean.deleteUser}" >

                                            <f:param name="testUserId" value="#{user.id}"></f:param>                                               

                                </p:commandButton>

                                <p:commandButton value="Not Yet" onclick="PF('confirmation').hide()"

                                            type="button" />

                    </p:confirmDialog>

豆: -

        public void deleteUser() {

                    String id = FacesContext.getCurrentInstance().getExternalContext()

                                                        .getRequestParameterMap().get("testUserId ");

        }           

1 个答案:

答案 0 :(得分:0)

使用属性操作侦听器:

<p:commandButton  value="Delete"  ajax="false" onclick="PF('confirmation').show()" type="button">
    <f:setPropertyActionListener value="#{tableRowVar}" target="#{bean.selectedUser}" />
</p:commandButton>

其中tableRowVar是dataTable中的var的名称,bean.selectedUser是bean中用于保存所选行的属性。从commandButton中删除操作,并将其保留在确认对话框的按钮中。

让我知道这是否有效。

相关问题