File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[SPRING] Java Bean doesn't get prepared

 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic