GeeCON Prague 2014*
The moose likes Other Application Frameworks and the fly likes [SPRING] Java Bean doesn't get prepared Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "[SPRING] Java Bean doesn Watch "[SPRING] Java Bean doesn New topic
Author

[SPRING] Java Bean doesn't get prepared

Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
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

Joined: Oct 18, 2000
Posts: 4121

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.)


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
Consider Paul's rocket mass heater.
 
subject: [SPRING] Java Bean doesn't get prepared