0

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?

Radnerus
  • 40
  • 3

1 Answers1

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
  • do you have a source for the `""` value? It would be helpful. – Marc-Andre Jul 15 '13 at 12:55
  • 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
  • 1
    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](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