title: How to display my application's errors in JSF?
body: <p>In my JSF/Facelets app, here's a simplified version of part of my form:</p>
  
  <pre><code>&lt;h:form id="myform"&gt;
    &lt;h:inputSecret value="#{createNewPassword.newPassword1}" id="newPassword1" /&gt;
    &lt;h:message class="error" for="newPassword1" /&gt;
    &lt;h:inputSecret value="#{createNewPassword.newPassword2}" id="newPassword2" /&gt;
    &lt;h:message class="error" for="newPassword2" /&gt;
    &lt;h:commandButton value="Continue" action="#{createNewPassword.continueButton}" /&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>I'd like to be able to assign an error to a specific h:message tag based on something happening in the continueButton() method. Different errors need to be displayed for newPassword and newPassword2. A validator won't really work, because the method that will deliver results (from the DB) is run in the continueButton() method, and is too expensive to run twice. </p>
  
  <p>I can't use the h:messages tag because the page has multiple places that I need to display different error messages. When I tried this, the page displayed duplicates of every message.</p>
  
  <p>I tried this as a best guess, but no luck:</p>
  
  <pre><code>public Navigation continueButton() {
    ...
    expensiveMethod();
    if(...) {
      FacesContext.getCurrentInstance().addMessage("newPassword", new FacesMessage("Error: Your password is NOT strong enough."));
    }
  }
  </code></pre>
  
  <p>What am I missing? Any help would be appreciated!</p>