title: Spring Webflow - Unable to invoke annotation validation on a model bean
body: <p>Please see the code snippet below. I My flow starts with display of a simple JSP with 3 fields. When i submit the form, i want the validations (JSR-303), configured via annotations on the form bean, to kick in and show the error messages. But that is not happening. The page is getting submitted to searchActions.findExistingPlayer method. Any pointers will help.</p>
  
  <p>Config file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Source project: sip05, branch: 03 (Maven Project) --&gt;
  
  &lt;flow xmlns="http://www.springframework.org/schema/webflow"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="
      http://www.springframework.org/schema/webflow
      http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
      start-state="findExistingPlayerForm"&gt;
  
      &lt;view-state id="findExistingPlayerForm"&gt;
          &lt;on-render&gt;
              &lt;evaluate expression="findExistingPlayerFormAction.setupForm"&gt;&lt;/evaluate&gt;
          &lt;/on-render&gt;
          &lt;transition on="find" to="findExistingPlayerFormActionState"&gt;
              &lt;evaluate expression="findExistingPlayerFormAction.bindAndValidate"&gt;&lt;/evaluate&gt;
          &lt;/transition&gt;
      &lt;/view-state&gt;
  
      &lt;action-state id="findExistingPlayerFormActionState"&gt;
          &lt;evaluate expression="searchActions.findExistingPlayer"&gt;&lt;/evaluate&gt;
          &lt;transition on="success" to="displayFindExistingPlayerResult"&gt;&lt;/transition&gt;
      &lt;/action-state&gt;
      &lt;view-state id="displayFindExistingPlayerResult"&gt;
          &lt;&lt;---Some transitions--&gt;&gt;&gt;
      &lt;/view-state&gt;
      &lt;end-state id="newSearchEndState" /&gt;
  
  &lt;/flow&gt;
  </code></pre>
  
  <p>Action mapping</p>
  
  <pre><code>&lt;bean id="findExistingPlayerFormAction" class="org.springframework.webflow.action.FormAction"&gt;
          &lt;property name="formObjectClass"
              value="com.saurabhd.springwebflow.form.PlayerSearchForm" /&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>Form:</p>
  
  <pre><code>public class PlayerSearchForm implements Serializable{
  private static final long serialVersionUID = 1L;
  
  
      private String firstName;
  
      private String lastName;
      private String homePhone;
  
      @NotEmpty
      @Size(min=10)
      public String getFirstName() {
          return firstName;
      }
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
      @NotNull
      public String getLastName() {
          return lastName;
      }
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      @NotBlank
      public String getHomePhone() {
          return homePhone;
      }
      public void setHomePhone(String homePhone) {
          this.homePhone = homePhone;
      }
  }
  </code></pre>
  
  <p>Web flow context:</p>
  
  <pre><code>&lt;flow:flow-builder-services id="flowBuilderServices"
          development="true" 
          validator="validator"/&gt;
  &lt;beans:bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/&gt;
  </code></pre>
  
  <p>JSP</p>
  
  <pre><code>&lt;%-- Source project: sip05, branch: 03 (Maven Project) --%&gt;
  &lt;%@ include file="/WEB-INF/jsp/taglibs.jspf" %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html 
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:spring="http://www.springframework.org/tags"
    xmlns:form="http://www.springframework.org/tags/form"&gt;
  
    &lt;head&gt;&lt;title&gt;Find Existing Player(s)&lt;/title&gt;&lt;/head&gt;
  
    &lt;body&gt;
      &lt;h2&gt;Search&lt;/h2&gt;          
      &lt;p&gt;
        Please fill the info below:
      &lt;/p&gt;
  
      &lt;form:form commandName="playerSearchForm" action="${flowExecutionUrl}"&gt;         
        &lt;label for="firstname"&gt;Player First Name&lt;/label&gt;
        &lt;form:input path="firstName" /&gt;&lt;br/&gt;
        &lt;form:errors path="firstName"/&gt; &lt;br/&gt;&lt;br/&gt;
  
        &lt;label for="lastName"&gt;Player Last Name&lt;/label&gt;
        &lt;form:input path="lastName" /&gt;&lt;br/&gt;
        &lt;form:errors path="lastName"/&gt; &lt;br/&gt;&lt;br/&gt;
  
  
  
        &lt;label for="homePhone"&gt;Home Phone:&lt;/label&gt;
        &lt;form:input path="homePhone" /&gt;&lt;br/&gt;
        &lt;form:errors path="homePhone"/&gt; &lt;br/&gt;&lt;br/&gt;
  
        &lt;input type="submit" name="_eventId_skip"
          value="Skip"/&gt;
        &lt;input type="submit" name="_eventId_find"
          value="Find"/&gt;            
      &lt;/form:form&gt;
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>An update - I have also tried the model binding in the view state. It also fails to invoke the JSR-303 annotation validations on my bean. :( </p>
  
  <p>What has worked so far is the custom <strong>validate${view-state-id}</strong> method. See below: </p>
  
  <pre><code>public void validateFindExistingPlayerForm(ValidationContext context){
          MessageContext messages = context.getMessageContext();
          if(StringUtils.isEmpty(firstName)){
              messages.addMessage(new MessageBuilder().error().source("firstName").
                      defaultText("Please enter the value for First Name.").build());
          }
      }
  </code></pre>
  
  <p>Flow.xml</p>
  
  <pre><code>&lt;var name="playerSearchForm" class="com.saurabhd.springwebflow.form.PlayerSearchForm"/&gt;
  
      &lt;view-state id="findExistingPlayerForm" model="playerSearchForm"&gt;
          &lt;transition on="find" to="findExistingPlayerFormActionState"&gt;
          &lt;/transition&gt;
      &lt;/view-state&gt;
  </code></pre>