title: Spring usage of typeMismatch messages
body: <p>I have done some searches on the web and in stackoverflow to see how to handle the following message that I get on one of my screens:</p>
  
  <blockquote>
    <p>Failed to convert property value of
    type [java.lang.String] to required
    type [java.lang.Long] for property
    'qtyToShip'; nested exception is
    java.lang.IllegalArgumentException:
    Could not parse number: Unparseable
    number: "a"</p>
  </blockquote>
  
  <p>From research and from looking at the web I assumed that adding the following to my errors.properties file would produce the desired results:</p>
  
  <pre><code>typeMismatch.shippingCommand.qtyToShip=1. Invalid value for Qty To Ship, accepts only numbers.  
  typeMismatch.qtyToShip=2. Invalid value for Qty To Ship, accepts only numbers. 
  shippingCommand.qtyToShip=3. Invalid value for Qty To Ship, accepts only numbers. 
  qtyToShip=4. Invalid value for Qty To Ship, accepts only numbers.
  
  
  typeMismatch.java.lang.NumberFormatException=5. Invalid value for {0}, accepts only numbers. 
  typeMismatch.java.lang.Integer=Must specify an integer value. 
  typeMismatch.java.lang.Long=Must specify an integer value. 
  typeMismatch.java.lang.Float=Must specify a decimal value. 
  typeMismatch.java.lang.Double=Must specify a decimal value.  
  typeMismatch.int=Invalid number entered 
  typeMismatch=Invalid type entered
  </code></pre>
  
  <p>I add integer values to the message to determine which one would show up.</p>
  
  <p>Now at the top of my JSP I have the following:</p>
  
  <pre><code>  &lt;center&gt;
      &lt;spring:hasBindErrors name="shippingCommand"&gt;
        &lt;c:if test="${errors.errorCount &gt; 0 }"&gt;
          &lt;h4&gt;Following errors need to be corrected:&lt;/h4&gt;
          &lt;font color="red"&gt;
            &lt;c:forEach items="${errors.allErrors}" var="error"&gt;
              &lt;spring:message code="${error.code}" arguments="${err.arguments}" text="${error.defaultMessage}"/&gt;&lt;br /&gt;
            &lt;/c:forEach&gt;
          &lt;/font&gt;
        &lt;/c:if&gt;
      &lt;/spring:hasBindErrors&gt;
    &lt;/center&gt;
  </code></pre>
  
  <p>The above is outside my Form, inside my Form I have the following (testing out ideals)</p>
  
  <p>
      </p>
  
  <p>So the results is that when I run my code to trigger the error, I see that inside my form I get the following message:</p>
  
  <pre><code>1. Invalid value for Qty To Ship, accepts only numbers.
  </code></pre>
  
  <p>Which comes from this:  typeMismatch.shippingCommand.qtyToShip</p>
  
  <p>The outside of the form displayes:</p>
  
  <pre><code>Invalid type entered
  </code></pre>
  
  <p>What I do not understand is why am I able to display the correct message inside my form but not outside?</p>
  
  <p>In the controller I have added the following:</p>
  
  <pre><code>@Override
  protected void initBinder(HttpServletRequest pRequest, ServletRequestDataBinder pBinder) throws Exception
  {
      NumberFormat numberFormat = NumberFormat.getInstance();
      pBinder.registerCustomEditor(Long.class, "qtyToShip", new CustomNumberEditor(Long.class, numberFormat, false));
  }
  </code></pre>
  
  <p>Thanks</p>