You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using @DateTimeFormat annotation with direct field access causes unhandled exception.
Keith Donald suggested trying without direct field access (i.e. using bean properties), and this fixes the problem.
The code to re-produce the issue is shown below. This can also be seen in the forum.
Attached file has complete eclipse web project example, without libraries.
Using new mvc schema:
<?xml version="1.0" encoding="UTF-8"?>
<beansxmlns="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-scanbase-package="springmvc.simple"/>
<!-- New Spring 3.0 tag to enable new Converter and Formatting Frameworks -->
<mvc:annotation-driven/>
<beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver">
<propertyname="prefix"value="/WEB-INF/views/" />
<propertyname="suffix"value=".jsp" />
</bean>
</beans>
With 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 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";
}
}
Barry Wilks opened SPR-7809 and commented
Using
@DateTimeFormat
annotation with direct field access causes unhandled exception.Keith Donald suggested trying without direct field access (i.e. using bean properties), and this fixes the problem.
The code to re-produce the issue is shown below. This can also be seen in the forum.
Attached file has complete eclipse web project example, without libraries.
Using new mvc schema:
With simple command class
and simple controller
Affects: 3.0 GA
Reference URL: http://forum.springsource.org/showthread.php?p=333754#post333754
Attachments:
Referenced from: commits d3d7634
The text was updated successfully, but these errors were encountered: