title: Displaying Primefaces confirmDialog from Backing Bean
body: <p>I have a Primefaces datatable and when the user clicks on a row, I display the data to edit in a form.
  If the user changes the data in the form and clicks on any other row i.e if there is dirty data, I need to popup a confirmDialog to show if the user wants to save the data / discard it.
  The confirmDialog does not display when I try to execute it from backing bean.
  Any help is appreciated!</p>
  
  <p>I have implemented it as follows:</p>
  
  <h2>.xhtml:</h2>
  
  <pre><code>&lt;p:dataTable id="tsTableId" value="#{transactionSetBean.studentList}" var="tsRow"
       selectionMode="single" selection="#{transactionSetBean.selectedEditRec}" rowKey="#{tsRow.id}" scrollRows="10"&gt;
      &lt;p:ajax event="rowSelect" listener="#{transactionSetBean.onRowSelect}" update=":transactionSetsForm:tsEntryFrmId"&gt;
      &lt;/p:ajax&gt;
  ..
  &lt;/p:dataTable&gt;
  </code></pre>
  
  <h2> ConfirmDialog:</h2>
  
  <pre><code>&lt;p:confirmDialog widgetVar="dataChangeDlg"  message="Save changes Or Cancel"&gt;                                
  &lt;p:commandButton value="Save Changes" oncomplete="PF('dataChangeDlg').hide();" 
            update=":transactionSetsForm:messages :transactionSetsForm:tsEntryFrmId" 
                action="#{transactionSetBean.updateRecord}" /&gt;
  &lt;p:commandButton value="Cancel"   onclick="PF('dataChangeDlg').hide();"                             
  
  &lt;/p:confirmDialog&gt;
  </code></pre>
  
  <h2>Backing Bean:</h2>
  
  <pre><code>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);
          }
      }
  </code></pre>