Announcement Announcement Module
Collapse
No announcement yet.
binding exception for parameter appearing in both form and url query string Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • binding exception for parameter appearing in both form and url query string

    I have a form like the following:

    Code:
    <form:form modelAttribute="command" action="myaction?year=2010" method="POST">
      <form:input path="year" value="2010" />
      <form:submit .../>
    </form>
    My command class is very simple, it has an Integer property year.

    My controller does not have any custom property editor registered except the default built-in ones.

    When the form is submitted, I get the following binding exception for the year property:

    Code:
    Failed to convert property value of type [java.lang.String[]] to 
    required type [java.lang.Integer] for property year; nested exception is 
    java.lang.NumberFormatException: For input string: "2010,2010"
    Looks like spring is trying to bind an array of strings to an integer because the name "year" appears in both form and the url query string.

    Is this expected binding behavior? If so, is there a way to explicitly specify which year it's binding to?
    Last edited by jacky.lu; Feb 18th, 2010, 02:50 PM.

  • #2
    There is no way to specify, because that is the way the http works. If it finds the same parameter twice it is treated as an array. The only option is to use 2 different parameters.

    Comment

    Working...
    X