title: JSF 2 - No way to do Required Inputs + Clear (Immediate) Button?
body: <p>This question is similar to the question <a href="https://stackoverflow.com/questions/7708041/jsf-immediate-true-for-cancel-button-doesnt-work">here</a> but that solution doesn't work here.</p>
  
  <p>Take this simple-to-the-max example:</p>
  
  <pre><code>&lt;h:form&gt;
    &lt;h:inputText required="true" value="#{mrBean.someValue}" /&gt;
    &lt;h:inputText required="true" value="#{mrBean.someValue2}" /&gt;
  
    &lt;h:commandButton value="Submit"&gt;
      &lt;f:ajax execute="@form" /&gt;
    &lt;/h:commandButton&gt;
    &lt;h:commandButton immediate="true" action="#{mrBean.clearAllValues}" value="Clear"&gt;
      &lt;f:ajax render="@form" /&gt;
    &lt;/h:commandButton&gt;
  
  &lt;/h:form&gt;
  </code></pre>
  
  <p>And the bean Code:</p>
  
  <pre><code>public void clearAllValues() {
      setSomeValue(null);
      setSomeValue2(null);
  }
  </code></pre>
  
  <p>Take this scenario:</p>
  
  <ul>
  <li>Enter 'X' value in first input</li>
  <li>Submit it using the 'Submit' Button. (failed in validation)</li>
  <li>Enter 'Y' into the same input.</li>
  <li>Click the 'Clear' button.</li>
  <li>Result: Inputs don't clear and value of first input returns to 'X'.</li>
  </ul>
  
  <p>I would expect this scenario to clear the input values but it doesn't, instead, it restores 'X' which is the previously submitted value. It actually never really runs <code>mrBean.getSomeValue()</code> on the bean (Which would have returned null and clear the input field)</p>
  
  <p>The problem is related to JSF not working well with required fields and immediate. I wonder if anyone managed to overcome this problem.</p>
  
  <p>Thanks!
  Ben.</p>