title: How to add ajax validation to programmatically generated primefaces component
body: <p>I am trying to attach normal bean validation to the blur event on a programmatically generated Primefaces UIComponent.   </p>
  
  <p>If I manually create the component using xhtml, which works fine, it looks like this:</p>
  
  <pre><code>&lt;p:inputText id="customerName" value="#{editCustomerBean.name}" label="Name"&gt;
      &lt;p:ajax async="true" event="blur" update="customerName, customerNameMsg" /&gt;
  &lt;/p:inputText&gt;
  </code></pre>
  
  <p>Unfortunately I need to generate this component on the fly because of some dynamic attributes that will be populated based on runtime data.  The code I wrote to try and exactly replicate this component:</p>
  
  <pre><code>UIInput input = new InputText();
  
  AjaxBehavior ajax = new AjaxBehavior();
  ajax.setAsync(true);
  ajax.setUpdate("customerName, customerNameMsg");
  input.addClientBehavior("blur", ajax);
  input.setId("customerName");
  input.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{editCustomerBean.name}", String.class));
  </code></pre>
  
  <p>When I generate this component in this way, I see a request sent to the server on the blur event, but no validation takes place.  The request which is posted looks identical to that which is sent when I specify the component in xhtml:</p>
  
  <pre><code>javax.faces.partial.ajax=true&amp;javax.faces.source=mainForm%3AcustomerName&amp;javax.faces.partial.execute=mainForm%3AcustomerName&amp;javax.faces.partial.render=mainForm%3AcustomerName+mainForm%3AcustomerNameMsg&amp;javax.faces.behavior.event=blur&amp;javax.faces.partial.event=blur&amp;mainForm%3AcustomerName=&amp;javax.faces.ViewState=8176624577669857830%3A-4154840965136338204
  </code></pre>
  
  <p>I have seen similar questions posted on this website and the Primefaces forums, but it usually involves attaching a listener method to the AjaxBehavior, which is not what I am trying to do here.  I would like the behavior to be the same as the  tag when no listener is specified, which is to validate the field.</p>