Displaying Primefaces confirmDialog from Backing Bean



我有一个Primefaces数据表,当用户单击一行时,我会在表单中显示要编辑的数据。如果用户更改表单中的数据并单击任何其他行,即如果有脏数据,我需要弹出一个confirmDialog来显示用户是否要保存/丢弃数据。当我尝试从backingbean执行confirmDialog时,它不会显示。感谢您的帮助!

我已经实现如下:

.xhtml:

<p:dataTable id="tsTableId" value="#{transactionSetBean.studentList}" var="tsRow"
     selectionMode="single" selection="#{transactionSetBean.selectedEditRec}" rowKey="#{tsRow.id}" scrollRows="10">
    <p:ajax event="rowSelect" listener="#{transactionSetBean.onRowSelect}" update=":transactionSetsForm:tsEntryFrmId">
    </p:ajax>
..
</p:dataTable>

ConfirmDialog:

<p:confirmDialog widgetVar="dataChangeDlg"  message="Save changes Or Cancel">                                
<p:commandButton value="Save Changes" oncomplete="PF('dataChangeDlg').hide();" 
          update=":transactionSetsForm:messages :transactionSetsForm:tsEntryFrmId" 
              action="#{transactionSetBean.updateRecord}" />
<p:commandButton value="Cancel"   onclick="PF('dataChangeDlg').hide();"                             
</p:confirmDialog>

背豆:

public void onRowSelect(SelectEvent event)
    {
        String actionName = ON_ROW_SELECT;
        try
        {
            Student selectedObj = (Student)event.getObject();
            if (selectedObj != null)
            {
                selectedEditRec = selectedObj;
            }
            // if data is changed then show the dataChange dialog 
            if (isDataChanged())
            {
                setShowDataChangedDialog(true);
                RequestContext context = RequestContext.getCurrentInstance();
                // execute javascript and show dialog
                context.execute("PF('dataChangeDlg').show();");
            }
        }
        catch (Exception e)
        {
            handleException(e);
        }
    }
RequestContext.getCurrentInstance().execute("PF('dataChangeDlg').show();");
<p:ajax event="rowSelect" listener="#{transactionSetBean.onRowSelect}" update=":transactionSetsForm:tsEntryFrmId">

对我有用。肯定是另一个错误。也许isDataChanged是false,更新中的组件id错误或其他什么。

使用PrimeFaces>=6.2

PrimeFaces.current().executeScript("PF('dataChangeDlg').show()");

最新更新