title: Ajax submit - select and focus field with validation error
body: <p>I'm trying to implement select (and focus) the component based on validation decision. </p>
  
  <p>For example:</p>
  
  <ul>
  <li>login form (2 inputs: username, password; 1 submit button)</li>
  <li>if the validation fail on <code>username</code>, <code>&lt;h:inputText id="name"&gt;</code> will be focused</li>
  <li>if the validation fail on <code>password</code>, <code>&lt;h:inputSecret id="password"&gt;</code> will be focused</li>
  <li>page will not be refreshed, submit is an <strong>ajax</strong> button</li>
  </ul>
  
  <p><strong>What I've tried:</strong></p>
  
  <p><strong>without</strong> ajax call (this is <strong><em>working fine</em></strong> - <code>componentId</code> is set in bean in validation proccess, and selected/focused after each page refresh/submit):</p>
  
  <pre><code>$(document).ready(function() {
    document.getElementById('form:#{bean.componentId}').focus();
    document.getElementById('form:#{bean.componentId}').select();
  });
  ...
  &lt;h:commandButton id="save" action="#{bean.save}" type="submit"/&gt;
  </code></pre>
  
  <p>BUT <strong>with</strong> ajax call:</p>
  
  <pre><code>function myFunc(data) {
    if (data.status == "success") {
      var element = document.getElementById('form:#{bean.componentId}');
      element.focus();
      element.select();
  }}
  ...
  &lt;h:commandButton id="save" action="#{bean.save}" type="submit"&gt;
    &lt;f:ajax execute="@form" render="@form" onevent="myFunc"/&gt;
  &lt;/h:commandButton&gt;
  </code></pre>
  
  <p>This way is also working, problem is, <code>componentId</code> is still the same (the one, which is inicialized during bean creation). </p>
  
  <p>Previous questions related to this topic:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/13540298/proccess-onclick-function-after-ajax-call-fajax">Proccess onclick function after ajax call </a></li>
  <li><a href="https://stackoverflow.com/questions/13539497/each-submit-button-calls-the-same-function">Each submit button calls the same function</a></li>
  </ul>
  
  <p>How can I use ajax submit button and select/focus to the field with validation error???</p>