Results 1 to 6 of 6

Thread: String to int - java.lang.NumberFormatException

  1. #1
    Join Date
    Jun 2005
    Posts
    4

    Default String to int - java.lang.NumberFormatException

    I have a Spring MVC SimpleFormController and a Validator which handle form submissions.

    I'm getting this error:
    Code:
    Failed to convert property value of type [[Ljava.lang.String;] to required type [int] for property 'year'; nested exception is java.lang.NumberFormatException: For input string: "0,"
    Doesn't Spring MVC support String to int conversion by default? At least according to documentation it should.

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Your string has a comma in it ("0,"). If these is valid for the locale, and you need to support custom property editors, you need to use a wrapper class.

  3. #3
    Join Date
    Jun 2005
    Posts
    4

    Default

    I did not even notice, or expect, the comma. It's not coming from my code. The values are coming from a select field and are pre-defined. They contain no commas.
    Code:
    <option value="2006" >
    2006
    </option>
    Where could the comma be coming from?

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Where could the comma be coming from?
    Possibly two HTML fields with the same name.

  5. #5
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Look at the HTML source as well.

  6. #6
    Join Date
    Jun 2005
    Posts
    4

    Default Duplicate fields in the HTML

    You were right I had two fields called year in the HTML form. Thanks a lot. I would probably have spent a day looking for the answer.

Similar Threads

  1. Replies: 17
    Last Post: Jan 2nd, 2007, 01:43 PM
  2. LDAPPasswordAuthenticationDao problem
    By benoit_m35 in forum Security
    Replies: 15
    Last Post: Jan 11th, 2006, 07:04 AM
  3. Replies: 8
    Last Post: Jul 13th, 2005, 11:20 AM
  4. URL parameters
    By adepue in forum Swing
    Replies: 5
    Last Post: Jan 17th, 2005, 01:36 PM
  5. Enlisting Custom DataSource with JTa
    By shaby775 in forum Data
    Replies: 11
    Last Post: Sep 9th, 2004, 03:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •