Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when combining <mvc:annotation-driven> and DataBinder.initdirectfieldaccess, conversion problems cause ConversionFailedException instead of being handled by the DataBinder [SPR-6953] #11618

Closed
spring-projects-issues opened this issue Mar 5, 2010 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 5, 2010

Hans Desmet opened SPR-6953 and commented

When you have the element mvc:annotation-driven/ in the bean definition file
and you use DataBinder.initDirectFieldAccess,
conversion problems are not handled by the DataBinder, but lead to a ConversionFaileException.

When you remove the element mvc:annotation-driven/, the DataBinder handles conversion problems OK.

Example command object:


package org.example.web;

public class CommandObject {
private int value;
public int getValue() {
return value;
}
}

Example controller


package org.example.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.DataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class ExampleController {
@RequestMapping(value="/example.htm",method=RequestMethod.GET)
public String example(Model model) {
model.addAttribute(new CommandObject());
return "/WEB-INF/JSP/example.jsp";
}
@RequestMapping(value="/example.htm",method=RequestMethod.POST)
public String example(@ModelAttribute CommandObject commandObject, BindingResult bindingResult) {
return "/WEB-INF/JSP/example.jsp";
}
@InitBinder
public void initBinder(DataBinder dataBinder) {
dataBinder.initDirectFieldAccess();
}
}

/WEB-INF/JSP/example.jsp


<?xml version="1.0" encoding="UTF-8"?>

<%@page contentType="text/html" pageEncoding="UTF-8" session="false"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<form:form commandName="commandObject">
<div><form:input path="value"/> <form:errors path="value"/></div>
<div><input type="submit" value="OK"/></div>
</form:form>
</body>
</html>

Steps to see the problem


Type blabla in the textbox and submit,
You get a HTTP 500
The stack trace shows a ConversionFailedException


Affects: 3.0.1

Referenced from: commits 53b6e1c

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This was an unfortunate oversight in 3.0: ConversionExceptions were properly detected for bean property access but not for direct field access. Fixed for 3.0.2 now.

This will be available in tonight's 3.0.2 snapshot. Feel free to give it an early try if you have the chance, and let me know whether it works for you.

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants