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?

5
  • Have you tried to see in debug to see what the value was? Commented 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 value Commented Jul 15, 2013 at 13:47
  • @DwB no value in the sense, will it be empty or null? Commented Jul 17, 2013 at 10:29
  • empty string will be the value. Commented 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. Commented Jul 18, 2013 at 9:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

do you have a source for the "" value? It would be helpful.
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.
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
@Matt, thx for the input. found a discussion with more info on StringTrimmerEditor - stackoverflow.com/questions/2977649/…
Please mark this old answer as 'accepted', it improves your reputation and encourages people to continue answering your questions in the future. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.