Results 1 to 8 of 8

Thread: Submission of empty form fields

  1. #1

    Default Submission of empty form fields

    I don't think form fields that are empty (0 length strings) should populate the form backing object. Currently I am getting empty string fields in my form rather then null. I don't know what you would get with empty non-string fields!

    Is their a way to change this behaviour or make it the default? Should I file this in jira somewhere?

    Cheers
    Steve

  2. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    Steve,

    You said empty form field shouldn't populate the form backing object. But if I read further, what I think you are saying is that you think it shoudl populate it with nulls, not as an empty string? But why is one inherently more correct than another? In any case, at this point it's a bit moot, as changing this kind of behaviour would change backwards compatibility...

    Regards,

  3. #3
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

    I agree with Colin - it's perfectly reasonable to expect that submitted forms with empty fields may need to be seen as empty strings on the backing object. For case by case needs you can cause null to be set on the object in one of the onBindAndValidate methods I think.
    Darren Davison.
    Public Key: 0xE855B3EA

  4. #4

    Default

    Quote Originally Posted by Colin Sampaleanu
    Steve,

    You said empty form field shouldn't populate the form backing object. But if I read further, what I think you are saying is that you think it shoudl populate it with nulls, not as an empty string? But why is one inherently more correct than another? In any case, at this point it's a bit moot, as changing this kind of behaviour would change backwards compatibility...

    Regards,
    I am sorry I was unclear. What I mean is that empty strings should be treated as nulls, I do not want empty strings populating my form object. The reason they are different is that they are different. I would need to make an extra test for every not-nullable field to make sure it is not-nullable AND not-empty. What is done in the case of, for example, a non-string object such as Integer? I imagine String fields are being treated differently then all others in this regard.

    My second wish would be that spring detected changed fields, and only populated the form object with user modified fields.

    I am certainly happy with treating empty strings as nulls as a configuration option (in order to preserve backwards compatibility).

  5. #5

    Default

    Quote Originally Posted by davison
    I agree with Colin - it's perfectly reasonable to expect that submitted forms with empty fields may need to be seen as empty strings on the backing object. For case by case needs you can cause null to be set on the object in one of the onBindAndValidate methods I think.
    I can certainly see the current behaviour as one reasonable approach (and the one taken obviously). However, current behaviour says that I supply a form object with null in a field, and get back a form object with an empty string in it's place even though the user did not change the field.

    Of course, you could argue that I could supply a form object with an empty string and get back null, but it seems to me a much less likely or harmful case. Hence, I would be happy with the behaviour being an option.

  6. #6

    Default

    Hey, I just discovered the StringTrimmerEditor, it looks like it already has the option to turn empty strings to null.

    Thanks!

  7. #7

    Default

    I'd suggest looking at Commons Lang, especially the StringUtils class. Become very familiar with it as it has become one of most useful classes I have used. It has a static method called trimToNullwhich will convert all empty strings to null for you. It has a ton of other methods which I have found to be invaluable in my programming. Best of all, no more NullPointerExceptions!

  8. #8
    Join Date
    Aug 2004
    Location
    Stockholm
    Posts
    466

    Default Hiyaa!

    Quote Originally Posted by steven.warren
    Hey, I just discovered the StringTrimmerEditor, it looks like it already has the option to turn empty strings to null.

    Thanks!
    Terrific! Just saved me a days work. Thanks!
    Sincerely,
    /The Cantor

    "Murphy was an optimist"
    (The O'Toole commentary on Murphy's Law)

Similar Threads

  1. Replies: 3
    Last Post: Jun 8th, 2010, 03:27 AM
  2. Replies: 6
    Last Post: Sep 24th, 2006, 11:58 AM
  3. Replies: 1
    Last Post: Sep 22nd, 2005, 04:42 AM
  4. Submitting empty field on form
    By strbuf in forum Web
    Replies: 11
    Last Post: Aug 11th, 2005, 07:29 PM
  5. Duplicate Form Submission
    By achalise in forum Web
    Replies: 3
    Last Post: Nov 15th, 2004, 08:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •