title: Primefaces p:calendar with p:ajax value not updated (one step delay)
body: <p>I want to call a bean after a date is selected in a <code>p:calendar</code>. In my setup I have a <code>@Named @ViewScoped</code> Bean, the class <code>ObWithDate</code> is a <code>@Entity</code> with a date field <em>validFrom</em>.</p>
  
  <pre><code>&lt;h:form id="fUser"&gt;
    &lt;p:dataTable id="dt" var="cum" value="#{myBean.listObWithDates}"&gt;
      &lt;p:column&gt;
        &lt;p:calendar id="cValidFrom" value="#{cum.validFrom}"&gt;  
          &lt;p:ajax event="dateSelect" listener="#{myBean.update(cum)}"
                  update=":fUser:dt"/&gt;  
        &lt;/p:calendar&gt;  
      &lt;/p:column&gt;
    &lt;/p:dataTable&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>The good thing is, that the bean method <code>update(ObWithDate myO)</code> is called with the correct object each time I select a date. The bad thing is, that <code>myO.validFrom</code> does not have the correct value. It's always <em>one step behind</em>:</p>
  
  <ul>
  <li>Field initialized with 2012-01-01</li>
  <li>GUI change to 2012-01-05, bean method debugs to 2012-01-01</li>
  <li>GUI change to 2012-01-15, bean method debugs to 2012-01-05</li>
  </ul>
  
  <p>This issue drives me crazy, I've found several issues with not correctly updated values and also some about <code>p:calendar</code>. Most of them suggest using the attribute <code>selectListener="#{calendarBean.handleDateSelect}"</code> with a  <code>handleDateSelect(DateSelectEvent event)</code> method. But I want to call my method since I want to pass the current instance of the variable.</p>
  
  <ul>
  <li>Firebug verifies, that the correct updated values are transmitted in a POST request</li>
  <li>I'm using Primefaces 3.2 and JBoss-7.1.1-Final</li>
  <li>Even without the <code>p:dataTable</code> and only using <code>p:calendar</code> the issue is still the same.</li>
  <li>The <em>wrong</em> value of the debug output can be observed for the method-Object <code>update(ObWithDate myO)</code> as well for the corresponding entry in <code>myBean.listObWithDates</code>.</li>
  <li><code>&lt;p:ajax immediate="true" .../&gt;</code> does not solve this issue.</li>
  </ul>
  
  <p><strong>Update</strong> MattHandy helped me a lot, the resulting question <em>How to get the corresponding list item in the ajax call inside the beans method?</em> is formulated in the followup <a href="https://stackoverflow.com/questions/10276602">JSF p:calendar in p:dataTable: How to get the row of p:ajax dateSelect event</a>.</p>