title: JSF Partial Screen Update processes full component tree
body: <p>I need some JSF / PrimeFaces (3.5) advice. </p>
  
  <p>We have a dynamic form, the form can be configured by a form builder, and the backing bean is a glorified <code>HashMap</code> with some additional getters and setters like (<code>getValueAsDate</code>/<code>setValueAsDate</code>). </p>
  
  <p>One of our field types allows for entering a number and when leaving the field additional information is requested and part of the form is updated. This appeared all to work nicely. </p>
  
  <pre><code>&lt;h:panelGroup id="clientInfo" layout="block" rendered="#{field.type == 'CLIENTINFO'}"&gt;
      &lt;h:outputLabel for="inputClientId"&gt;#{field.label}&lt;/h:outputLabel&gt;
      &lt;p:inputText id="inputClientId" maxlength="9" value="#{handler.property(field.id).value}"&gt;
          &lt;p:ajax listener="#{handler.fetchClientDetails(field.id)}" partialSubmit="true" process="@this" update="@parent,:mainform:msgs"
      &lt;/p:inputText&gt;
      &lt;!-- Additional output text elements to display the name, address etc. --&gt;
  &lt;/h:panelGroup&gt;
  </code></pre>
  
  <p>Recently we added a field which allowed for entering a <code>java.util.Date</code> using the PrimeFaces date picker component. After adding this field type the partial update stopped working. </p>
  
  <pre><code>&lt;h:panelGroup id="date" layout="block" rendered="#{field.type == 'DATE'}"&gt;
      &lt;h:outputLabel for="inputDate"&gt;#{field.label}&lt;/h:outputLabel&gt;
      &lt;p:calendar id="inputDate" value="#{handler.property(field.id).valueAsDate}" pattern="dd-MM-yyyy" maxlength="10"&gt;
          &lt;f:convertDateTime pattern="dd-MM-yyyy" /&gt;
      &lt;/p:calendar&gt;
  &lt;/h:panelGroup&gt;
  </code></pre>
  
  <p>When inspecting the partial result from the server we got something like the following (where 12345 is the clientId entered in the field above). </p>
  
  <pre><code>&lt;partial-response&gt;
      &lt;error&gt;
          &lt;error-name&gt;class java.text.ParseException&lt;/error-name&gt;
          &lt;error-message&gt;&lt;![CDATA[Unparseable date: "12345"]]&gt;&lt;/error-message&gt;
      &lt;/error&gt;
  &lt;/partial-response&gt;
  </code></pre>
  
  <p>The question is basically why is it even calling the <code>getValueAsDate</code> method for a field that isn't a <code>Date</code> or when there is even no date field type on the screen? It is probably something I'm missing (or misunderstanding) about the JSF Lifecycle or how partial updates work in JSF / PrimeFaces.</p>
  
  <h2>Update #1:</h2>
  
  <p>Just noticed in another debugging session that this isn't only happening for a partial update but already when initially rendering the screen. It appears as if all EL expressions are evaluated all the time, this also results in additional properties in my backing object (when a property is requested and it doesn't exists it is created with the value <code>null</code>).</p>
  
  <h2>Update #2:</h2>
  
  <p>The code to render the configured fields uses a <code>ui:repeat</code> en conditional <code>ui:fragment</code>s (tried <code>h:panelGroup</code>s as well) to render the specific input element for the configured field.</p>
  
  <pre><code>&lt;ui:repeat value=#{handler.formFields} var="field"&gt;
      &lt;ui:fragment rendered="field.type == 'DATE'&gt;
          &lt;!-- Specific fragment for date field --&gt;
      &lt;/ui:fragment&gt;
      &lt;ui:fragment rendered="field.type == 'TEXT'&gt;
      &lt;/ui:fragment&gt;
      &lt;ui:fragment rendered="field.type == 'REGEXP'&gt;
      &lt;/ui:fragment&gt;
      &lt;ui:fragment rendered="field.type == 'CLIENT'&gt;
      &lt;/ui:fragment&gt;
  &lt;/ui:repeat&gt;
  </code></pre>
  
  <p>Tried both <code>h:panelGroup</code> and <code>ui:fragments</code> combinations of the 2. </p>