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?
-
Have you tried to see in debug to see what the value was?Marc-Andre– Marc-Andre2013-07-15 12:56:02 +00:00Commented Jul 15, 2013 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 valueDwB– DwB2013-07-15 13:47:35 +00:00Commented Jul 15, 2013 at 13:47
-
@DwB no value in the sense, will it be empty or null?Radnerus– Radnerus2013-07-17 10:29:38 +00:00Commented Jul 17, 2013 at 10:29
-
empty string will be the value.DwB– DwB2013-07-17 13:21:03 +00:00Commented Jul 17, 2013 at 13:21
-
Thanks DwB.Ya i am getting empty string as value. used StringTrimmerEditor to convert that empty to null value.Radnerus– Radnerus2013-07-18 09:43:35 +00:00Commented Jul 18, 2013 at 9:43
Add a comment
|
1 Answer
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.
5 Comments
Marc-Andre
do you have a source for the
"" value? It would be helpful.Marc-Andre
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.Matt
Oh 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
Radnerus
@Matt, thx for the input. found a discussion with more info on StringTrimmerEditor - stackoverflow.com/questions/2977649/…
Matt
Please mark this old answer as 'accepted', it improves your reputation and encourages people to continue answering your questions in the future. Thank you.