在带有确认框的数据网格中删除按钮,点击确认框的是将参数值传递给bean



我们使用的是Primefaces 5

我们有一个数据网格搜索结果。在数据网格中,每一行都有一个删除按钮。在点击删除按钮时,当用户点击确认对话框中的yes按钮时,将显示一个确认框,这时应该调用bean的deleteUser方法,并删除参数id为' testUserId '的用户。问题是发送给bean的' testUserId '的值始终是数据网格最后一行的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 ");
        }           

使用属性操作监听器:

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

其中tableRowVar是数据表和bean中变量的名称。selectedUser是bean中的一个属性,它将保存选定的行。从命令按钮中删除操作,并将其保留在确认对话框的按钮中。

最新更新