The display of privities confirms the dialog using Bean

I have a Primefaces file and when the user clicks on the line, I show the data for editing in the form. If the user changes the data in the form and clicks on any other line. If there is dirty data, I need a Dialog confirmation popup to show if the user wants to save the data / discard it. ConfirmDialog is not displayed when I try to execute it using a bean. Any help is appreciated!

I implemented it as follows:

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

Bean Support:

 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); } } 
+6
source share
2 answers
 RequestContext.getCurrentInstance().execute("PF('dataChangeDlg').show();"); <p:ajax event="rowSelect" listener="#{transactionSetBean.onRowSelect}" update=":transactionSetsForm:tsEntryFrmId"> 

works for me. There must be another mistake. Perhaps isDataChanged is a false, incorrect identifier for the components in the update, or something.

+5
source

With PrimeFaces> = 6.2

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

Source: https://habr.com/ru/post/971056/


All Articles