title: Primefaces incell editing in dataTable with 2 dependent selectOneMenus doesn't save changes
body: <p>I have a <code>&lt;p:dataTable&gt;</code> with incell editing, it contains 2 columns each with a <code>&lt;h:selectOneMenu&gt;</code> plus a third Edit column. The second <code>&lt;h:selectOneMenu&gt;</code> is dependent on the selection in the first <code>&lt;h:selectOneMenu&gt;</code>. When a row is in input/edit mode, changing the value in the first <code>&lt;h:selectOneMenu&gt;</code> should update the list in the second <code>&lt;h:selectoneMenu&gt;</code>, I should then be able to continue to change the value in the second and then save changes on the row.</p>
  
  <p>My problem is, if the value in the first <code>&lt;h:selectOneMenu&gt;</code> is changed, the list in second <code>&lt;p:selectOneMenu&gt;</code> is updated correctly, but nothing happen when I click on the check icon (save changes) in <code>&lt;p:rowEditor&gt;</code> column, the row stays in editing mode. The RowEditEvent listener in the backing bean is (obviously) not invoked as well. I'm still able to click on the close icon to switch the row back to output mode however, but then nothing is saved.</p>
  
  <p>If I only change the value in the second <code>&lt;h:selectOneMenu&gt;</code> without changing the value in the first <code>&lt;h:selectOneMenu&gt;</code>, then there is no problem saving the changes.</p>
  
  <p>The followings are code snippets, simplified, and still "dirty" due to days of testing codes:</p>
  
  <p><code>xhtml:</code></p>
  
  <pre><code>&lt;h:form id="dataListForm"&gt;
  &lt;p:dataTable id="dataTable" value="#{bean.rdcList}" var="rdc" &gt;
      &lt;p:ajax event="rowEdit" listener="#{bean.onRowEdit}" /&gt;
      &lt;f:facet name="header"&gt;
          Data List
      &lt;/f:facet&gt;
      &lt;p:column headerText="Agency"&gt;
          &lt;p:cellEditor&gt;
              &lt;f:facet name="output"&gt;
                  &lt;h:outputText value="#{rdc.agency.descr}" /&gt;
              &lt;/f:facet&gt;
              &lt;f:facet name="input"&gt;
                  &lt;h:selectOneMenu value="#{rdc.agency.id}" valueChangeListener="#{bean.agChanged}"&gt;
                      &lt;f:selectItems value="#{bean.agenciestab}" var="ag" itemValue="#{ag.id}" itemLabel="#{ag}" /&gt;
                      &lt;p:ajax event="change" update="zoneSelect" /&gt;
                  &lt;/h:selectOneMenu&gt;
              &lt;/f:facet&gt;
          &lt;/p:cellEditor&gt;
      &lt;/p:column&gt;
      &lt;p:column headerText="Zone"&gt;
          &lt;p:cellEditor&gt;
              &lt;f:facet name="output"&gt;
                  &lt;h:outputText value="#{rdc.zone.id} - #{rdc.zone.name}" /&gt;
              &lt;/f:facet&gt;
              &lt;f:facet name="input"&gt;
                  &lt;h:selectOneMenu id="zoneSelect" value="#{rdc.zone.id}" valueChangeListener="#{bean.zChanged}"&gt;
                      &lt;f:selectItems value="#{bean.zonestab}" var="z" itemValue="#{z.id}" itemLabel="#{z}" /&gt;
                  &lt;/h:selectOneMenu&gt;
              &lt;/f:facet&gt;
          &lt;/p:cellEditor&gt;
      &lt;/p:column&gt;
      &lt;p:column headerText="Edit"&gt;
          &lt;p:rowEditor /&gt;
      &lt;/p:column&gt;
  &lt;/p:dataTable&gt;
  </code></pre>
  
  <p></p>
  
  <p><code>bean:</code></p>
  
  <pre><code>@ManagedBean(name = "bean")
  @SessionScoped
  
  public class Bean implements Serializable {
  .
  .
  /* Init */
  @PostConstruct
  public void init() {
      aChanged = false;
      zChanged = false;
      edited = false;
      agenciestab = new ArrayList&lt;SelectItem&gt;();
      for (Agency agency : agencyDao.all()) {
          agenciestab.add(new SelectItem(agency.getId(), agency.getDescr()));
      }
  }
  
  /* Listeners */
  public void agChanged(ValueChangeEvent event) {
      aChanged = true;
      selectedAgency = agencyDao.get(Integer.valueOf(event.getNewValue()
              .toString()));
      zonestab = new ArrayList&lt;SelectItem&gt;();
      if (selectedAgency != null) {
          for (Zone zone : zoneDao.getByDistrict(selectedAgency.getDistrict())) {
              zonestab.add(new SelectItem(zone.getId(), zone.getZone()+ " - " + zone.getName()));
          }
      } else {
          for (Zone zone : zoneDao.getByDistrict(rdcList.getRowData().getAgency().getDistrict())) {
              zonestab.add(new SelectItem(zone.getId(), zone.getZone()+ " - " + zone.getName()));
          }
      }
  }
  
  public void zChanged(ValueChangeEvent event) {
      zChanged = true;
      selectedZone = zoneDao.get(Integer.valueOf(event.getNewValue().toString()));
  }
  
  public void onRowEdit(RowEditEvent event) {
      edited = true;
      Rdc rdc = (Rdc) event.getObject();
      if (aChanged) {
          rdc.setAgency(selectedAgency);
          aChanged = false;
      }
      if (zChanged) {
          rdc.setZone(selectedZone);
          zChanged = false;
      }
      try {
          rdcDao.saveOrUpdate(rdc);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  /* Getters &amp; Setters */
  public DataModel&lt;Rdc&gt; getRdcList() {
      if (rdcList == null) {
          rdcList = new ListDataModel&lt;Rdc&gt;(rdcDao.getBatchRdc(batchBean.getCurBatch().getId()));
      } else {
          rdcList.setRowIndex(0);
          if (rdcList.isRowAvailable() &amp;&amp; rdcList.getRowData().getBatch().getId().equals(batchBean.getCurBatch().getId())) {
              if (edited) {
                  edited = false;
                  rdcList = new ListDataModel&lt;Rdc&gt;(
                          rdcDao.getBatchRdc(batchBean.getCurBatch().getId()));
              }
          } else {
              rdcList = new ListDataModel&lt;Rdc&gt;(rdcDao.getBatchRdc(batchBean.getCurBatch().getId()));
          }
      }
      return rdcList;
  }
  
  public void setRdcList(DataModel&lt;Rdc&gt; rdcList) {
      this.rdcList = rdcList;
  }
  
  public ArrayList&lt;SelectItem&gt; getAgenciestab() {
      return agenciestab;
  }
  
  public void setAgenciestab(ArrayList&lt;SelectItem&gt; agenciestab) {
      this.agenciestab = agenciestab;
  }
  
  public ArrayList&lt;SelectItem&gt; getZonestab() {
      zonestab = new ArrayList&lt;SelectItem&gt;();
      if (aChanged &amp;&amp; selectedAgency != null) {
          for (Zone zone : zoneDao.getByDistrict(selectedAgency.getDistrict())) {
              zonestab.add(new SelectItem(zone.getId(), zone.getZone()+ " - " + zone.getName()));
          }
      } else if (!aChanged) {
          for (Zone zone : zoneDao.getByDistrict(rdcList.getRowData().getAgency().getDistrict())) {
              zonestab.add(new SelectItem(zone.getId(), zone.getZone()+ " - " + zone.getName()));
          }
      }
  
      return zonestab;
  }
  
  public void setZonestab(ArrayList&lt;SelectItem&gt; zonestab) {
      this.zonestab = zonestab;
  }
  /* other getters &amp; setters */
  }
  </code></pre>
  
  <p>I'm using primefaces-3.1.1, mojarra-2.1.3-FCS and Tomcat 7.0.26</p>
  
  <p>Where did I do wrong? And is there a cleaner and better way of achieving what I'm trying to achieve?</p>