Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6324427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:42:03+00:00 2026-05-24T16:42:03+00:00

I have been trying out the new Spring MVC 3.0 Type Conversion Framework. I

  • 0

I have been trying out the new Spring MVC 3.0 Type Conversion Framework. I cannot find out how to trap conversion errors.

I am using the new mvc schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

     <!-- Scan this package and sub-packages for Annotated Controllers -->
     <context:component-scan base-package="springmvc.simple"/>             

     <!-- New Spring 3.0 tag to enable new Converter and Formatting Frameworks -->             
     <mvc:annotation-driven/>

     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/views/" />
      <property name="suffix" value=".jsp" />
     </bean>

    </beans>

And a simple command class:

public class Amount {

 @NumberFormat(style=Style.CURRENCY)
 @Min(0)
 private BigDecimal amount = BigDecimal.valueOf(10000, 2);

 @DateTimeFormat(iso=ISO.DATE)
 private Date date = new Date();

 public Date getDate() {
  return date;
 }

 public BigDecimal getAmount() {
  return amount;
 }

}

And an equally simple controller:

@Controller
@RequestMapping(value="/addVat.html")
public class AddVatController {

 @InitBinder
 public void initBinder(WebDataBinder binder) {
  binder.initDirectFieldAccess();
    }

 @RequestMapping(method = RequestMethod.GET)
 public String setupForm(Model model) {
  model.addAttribute("commandBean", new Amount());
  return "addVatForm";
 }

 @RequestMapping(method = RequestMethod.POST)
 public String onSubmit(@ModelAttribute("commandBean") @Valid Amount commandBean, BindingResult amountBinding, Model model) {

  if (amountBinding.hasErrors()) {
   return "addVatForm";
  }

  BigDecimal result = commandBean.getAmount().multiply(new BigDecimal("1.175"));
  model.addAttribute("result", result);

  return "result";
 }
}

This works fine – I get validation error in my result.jsp if I enter a negative value for the BigDecimal. However if I try to send a Date such as 2010-07-024, which does not conform to ####-##-##, I get an error:

org.springframework.core.convert.ConversionFailedException: Unable to convert value 2010-07-024 from type 'java.lang.String' to type 'java.util.Date'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value 2010-07-024 from type 'java.lang.String' to type 'java.util.Date'; nested exception is java.lang.IllegalArgumentException: Invalid format: "2010-07-024" is malformed at "4"
 org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:40)
 org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:135)
 org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:199)
 org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:169)
 org.springframework.beans.DirectFieldAccessor.setPropertyValue(DirectFieldAccessor.java:125)
 org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(AbstractPropertyAccessor.java:50)
 org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
 org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:665)
 org.springframework.validation.DataBinder.doBind(DataBinder.java:561)
 org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:190)
 org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:110)
 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.doBind(AnnotationMethodHandlerAdapter.java:696)
 org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:744)
 org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:296)
 org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:163)
 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
 org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Which is fine – but how do I trap the error? I was expecting BindingResult to simply contain another error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:42:06+00:00Added an answer on May 24, 2026 at 4:42 pm

    According to Juergen Hoeller, this was fixed in Spring 3.0.2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to Emacs and I have been trying to figure out
I have been trying to find out why the following lines of code do
I have been trying to find out what the difference is between the IS
I'm new to Django (and Python) and I have been trying to work out
I have been trying to find out how to bind data to a System.Windows.Forms.DomainUpDown()
I obviously new and have been trying to two days to figure out how
I have been trying out the NameValueDeserializer from MVCContrib, which will take a IList
I have been trying to figure out a solution but nothing has really presented
I have been trying to figure out a way to tag several methods from
I have been trying to figure this out for way to long tonight. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.