title: JSF: How validate fields and return error messages by bean validation?
body: <p>I have a contact form and I have some fields that are validated by bean validation, how could I return bean validation error messages after submitting?</p>
  
  <p>For example:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;h:form&gt;
      &lt;h:inputText id="name" value="#{contact.client.name}"&gt;&lt;/h:inputText&gt;Name (Required)
      &lt;h:inputText id="email" value="#{contact.client.email}"&gt;&lt;/h:inputText&gt;E-Mail (Required)
      &lt;h:inputText id="website" value="#{contact.client.website}"&gt;&lt;/h:inputText&gt;Website (Optional)
      &lt;h:inputText id="text" value="#{contact.client.text}"&gt;&lt;/h:inputText&gt;Message (Required):
  
      &lt;h:commandButton value="Send" action="#{contact.sendMessage}" &gt;
          &lt;f:ajax execute="@form" render="@form"/&gt;
      &lt;/h:commandButton&gt;
  
  &lt;/h:form&gt;
  </code></pre>
  
  <p>This is how I'm validating my fields:</p>
  
  <pre><code>        // Client.java (model)
      @NotNull(message="Please provide your name")
      private String name;
  
      @NotNull(message="Please provide your email")
      @Pattern(regexp = "([^.@]+)(\\.[^.@]+)*@([^.@]+\\.)+([^.@]+)", message = "Invalid e-mail")
      private String email;
  
      @Pattern(regexp = "(http[s]?://|ftp://)?(www\\.)?[a-zA-Z0-9-\\.]+\\.([a-zA-Z]{2,5})$", message = "Not valid URL")
      private String website;
  
      @NotNull(message="Please provide your message")
      private String text;
  </code></pre>