title: Primefaces Datatable item selection, confirmation dialog and RequestContext
body: <p><strong>EDIT:</strong> Everything worked after I tried to populate the collection when the view is constructed, in the @PostContsruct init()-method of that view's backing bean class. It is @ViewScoped. So the problem lies in that the component somehow doesn't recognize the collection that is used as a value of the datatable, actually having values because it is populated in an uncommon way. Anyway, everything works perfectly if I populate the collection when the view builds. <strong>But of course that's not a solution because the collection must be populated on that mentioned blur ajax event.</strong> So it's some kind of a lifecycle / scope problem.</p>
  
  <p><strong>EDIT2:</strong> I tried to add the table to the same form as the component that has ajax blur effect in it, showing the popup and the datatable in that popup and populating the collection. That worked too. So, somehow the lifecycle / scope was different in that ajax blur event and the datatable functionality since they were in different forms. Now I should somehow manage to keep them in the same scope while having the datatable in the popup dialog. Now the datatable clumsily resides in the same form for aforementioned testing purposes.</p>
  
  <p>I have a Primefaces <code>p:dataTable</code> in a <code>p:confirmDialog</code> and when I select an item, the setter of that item just gets <code>null</code> value. So a <code>null</code> value is set and the following operation obviously doesn't work because we don't have a value to work with.</p>
  
  <p>I think the problem has something to do with me having to use <code>RequestContext</code> to show the dialog. This is because the dialog should be shown when a collection is checked in a <code>blur</code> event of a <code>form</code>.</p>
  
  <p>First, a <code>blur</code> event is checked from a InputText:</p>
  
  <pre><code>&lt;p:inputText id="customerIdInput"
               value="#{newCustomerCaseController.id}"
               label="custId" required="true"&gt;
      &lt;f:ajax event="blur" listener="#{newCustomerCaseController.performBackgroundSearch}" /&gt;
  &lt;/p:inputText&gt;
  </code></pre>
  
  <p>Then, on that <code>blur</code> event a listener method will be called in the backing bean, which shows a dialog via <code>RequestContext</code> as follows:</p>
  
  <pre><code>public void performBackgroundSearch() {
      showPopUpBecauseCertainConditionsAreMet();
  }
  
  public void showPopUpBecauseCertainConditionsAreMet() {
  
      setExistingCustomerCases(customerCaseService.searchByEmployerId(employerId));
      RequestContext.getCurrentInstance().update("caseform");
      RequestContext.getCurrentInstance().execute(
              "PF('employerAlreadyHasCustomerCasesDialog').show()");
      }
  }
  </code></pre>
  
  <p>Here's the confirm dialog and table in xhtml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;p:confirmDialog widgetVar="employerAlreadyHasCustomerCasesDialog" width="500" appendTo="@(body)" showEffect="fade" hideEffect="fade"
                   closable="false" &gt;
  &lt;h:form id="caseform"&gt;
          &lt;p:dataTable id="casetable"  var="custcase" rowKey="#{custcase.caseId}" value="#{newCustomerCaseController.existingCustomerCases}"
                       selectionMode="single" selection="#{newCustomerCaseController.selectedAlreadyExistingCustomerCase}" &gt;
              &lt;p:ajax event="rowSelect" process="@this" listener="#{newCustomerCaseController.onExistingCaseRowSelect()}" /&gt;
              &lt;p:column headerText="caseId"&gt;
                  &lt;h:outputText value="#{custcase.caseId}" /&gt;
              &lt;/p:column&gt;
          &lt;/p:dataTable&gt;
  &lt;/h:form&gt;
  &lt;!--some unimportant buttons which we don't touch in this example--&gt;
  &lt;/p:confirmDialog&gt;
  </code></pre>
  
  <p>Lastly, let's see what the <code>onExistingCaseRowSelect</code> listener method does. It only tries to redirect, as in navigate to different url using the <code>caseId</code> of that <code>customerCase</code> that we try to select in the <code>p:dataTable</code>.</p>
  
  <pre><code>public void onExistingCaseRowSelect(SelectEvent event) {
      try {
          facesContext.getExternalContext().redirect("/customercase.xhtml?caseId=" + selectedAlreadyExistingCustomerCase.getCaseId());
      }catch (Exception e) {
      }
  }
  </code></pre>
  
  <p>The problem here is that the <code>selectedAlreadyExistingCustomerCase</code> doesn't get set in the backing bean when it is clicked in the table. <strong>A <code>null</code> is being set when I click the row in the table.</strong> I've checked this with printlines in getter and setter. I think the problem here is that something happens because of the update of the view via <code>RequestContext.getCurrentInstance().update("componentName");</code></p>
  
  <p>How can I get the clicked row value in the table - a <code>customerCase</code> that is - to be set as the selected value in the backing bean, instead of a <code>null</code>?</p>