I am using spring's bind tld to map a textbox to the java model object's property. When no value is entered in the text box and submit action is done, what value will be set in the model property? property is declared as type String. I am not setting any default value to the text box. Is empty value set or "" is set?
Asked
Active
Viewed 460 times
0
-
Have you tried to see in debug to see what the value was? – Marc-Andre Jul 15 '13 at 12:56
-
If by "text box" you mean an input with type="text", then when the form is submitted, a property is included in the posted form data for the input control with no value – DwB Jul 15 '13 at 13:47
-
@DwB no value in the sense, will it be empty or null? – Radnerus Jul 17 '13 at 10:29
-
empty string will be the value. – DwB Jul 17 '13 at 13:21
-
Thanks DwB.Ya i am getting empty string as value. used StringTrimmerEditor to convert that empty to null value. – Radnerus Jul 18 '13 at 09:43
1 Answers
1
Submitted form values which are of type String
are by default submitted as ""
.
You can register Spring's StringTrimmerEditor
to ensure that empty values are converted to null
if you like.

Matt
- 65
- 2
- 9
-
-
Sorry I meant : Where have you take the info about the default value being `""`? It could be helpful to have a link to your source. Is it clear ? I'm not a English native speaker. – Marc-Andre Jul 15 '13 at 13:51
-
1Oh right, I only know from experience. All values are submitted as text and if they are empty then empty strings. Property editors are used to convert values to data types other than Strings. There are lots of default property editors configured which handle most standard types e.g. Double, Integer, etc... The Spring documentation is very good, look at [7.4.2 Built-in PropertyEditor implementations](http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/validation.html#beans-beans-conversion) – Matt Jul 15 '13 at 14:29
-
@Matt, thx for the input. found a discussion with more info on StringTrimmerEditor - http://stackoverflow.com/questions/2977649/is-there-an-easy-way-to-turn-empty-java-spring-form-input-into-null-strings – Radnerus Jul 17 '13 at 10:35
-
Please mark this old answer as 'accepted', it improves your reputation and encourages people to continue answering your questions in the future. Thank you. – Matt Nov 13 '13 at 09:18