• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
  • Himai Minh

[SPRING] Java Bean doesn't get prepared

Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Spring 1.2.7, Hibernate 3 and Apache Tomcat 5.5.
I have created simple user registration page having different fields like email Address, First Name, Last Name, Phone Number, Zip Code etc.
The problem is, one the field (Integer phonenumber) of bean doesn't get set when I hit the submit button of JSP page.
-- I have checked Spring binding on JSP.
-- I have checked field name (phonenumber) twice.

I am also using one validator class for this registration form. In that class I am trying to print the value of different fields. I get values of all the fields except phonenumber.

Here is some debugging from my side.
1) I have kept SOPs (System.out.Println) in setter method of phonenumber and it gets called when I start the tomcat.
2) Setter method of all the fields get called when I hit the submit button and before going to validator class.

Here is my code excerpt.

1) Registration.jsp

2) Buyer.java (Bean)

3) Buyer.hbm.xml

I forgot to add the error message on my JSP page.

Failed to convert property value of type [java.lang.String] to required type [java.lang.Integer] for property phonenumber1; nested exception is java.lang.NumberFormatException: For input string: "111111111"

PS : I have asked this question here too.

I can provide more information if required.
I have spend/waste enough time.
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read about binding numbers on command objects. You'll need to set up a CustomNumberEditor in the initBinder() method of your controller. (Also, there's not really any reason to treat phone number as a Integer - String is fine, because even though a phone number is made up of numerical characters, you'll never do any mathematical computations on them. And there may be additional requirements related to formatting, international numbers, extensions, etc.)
I like tacos! And this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
    Bookmark Topic Watch Topic
  • New Topic