【问题标题】:Displaying Primefaces confirmDialog from Backing Bean从 Backing Bean 显示 Primefaces confirmDialog
【发布时间】:2014-08-10 01:44:10
【问题描述】:

我有一个 Primefaces 数据表,当用户单击一行时,我会在表单中显示要编辑的数据。 如果用户更改表单中的数据并单击任何其他行,即如果有脏数据,我需要弹出一个确认对话框以显示用户是否要保存数据/丢弃它。 当我尝试从支持 bean 执行它时,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>

确认对话框:

<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>

支持 Bean:

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);
        }
    }

【问题讨论】:

    标签: jsf jsf-2 primefaces datatable


    【解决方案1】:

    使用 PrimeFaces >= 6.2

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

    【讨论】:

      【解决方案2】:
      RequestContext.getCurrentInstance().execute("PF('dataChangeDlg').show();");
      
      <p:ajax event="rowSelect" listener="#{transactionSetBean.onRowSelect}" update=":transactionSetsForm:tsEntryFrmId">
      

      为我工作。 一定有另一个错误。也许 isDataChanged 是假的,更新中的组件 ID 错误或其他什么。

      【讨论】:

        猜你喜欢
        • 2014-03-16
        • 1970-01-01
        • 2015-10-05
        • 2015-12-10
        • 1970-01-01
        • 1970-01-01
        • 2020-06-18
        • 2012-12-26
        • 1970-01-01
        相关资源
        最近更新 更多