Spring Framework
  1. Spring Framework
  2. SPR-9244

Support for form submissions with field names that follow JavaScript object notation

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 3.1.1
    • Fix Version/s: None
    • Component/s: Core, Web
    • Last commented by a User:
      false

      Description

      JavaScript/Ajax frameworks such as jQuery serialize Javascript Objects as form parameters using indexed object notation (because in JavaScript, every object acts like a map). For example, the following JS object:

      var object = {
        connection : {
          provider: 'facebook',
          user_id: 1256789,
          access_token: 'foo'
        }
      }
      

      Gets serialized as form parameters:

      connection[provider]=facebook&connection[user_id]=1256789&connection[access_token]=foo
      

      It would be helpful if this format could auto-bind to the root form object's 'connection' property of type JavaBean, which would have nested properties 'provider', 'userId', and 'accessToken'. JSR303 validation could then be easily run against that nested bean's properties for example. BeanWrapper can only map the above to a loosely typed Map now--I have to convert to a strongly typed JavaBean manually.

        Issue Links

          Activity

          Hide
          Rossen Stoyanchev added a comment -

          Keith, a very minimal project at the issue repository would be very helpful.

          Show
          Rossen Stoyanchev added a comment - Keith, a very minimal project at the issue repository would be very helpful.
          Hide
          Rossen Stoyanchev added a comment -

          Corrected the example variable above to match the resulting serialized form.

          Although BeanWrapperImpl can map the above to a Map, the more general syntax can include more deeply nested objects. I've created an issue project. The README page contains the output of more examples.

          Show
          Rossen Stoyanchev added a comment - Corrected the example variable above to match the resulting serialized form. Although BeanWrapperImpl can map the above to a Map, the more general syntax can include more deeply nested objects. I've created an issue project . The README page contains the output of more examples.
          Hide
          Rossen Stoyanchev added a comment -

          Since POST and PUT tend to send data in the body of the request, the jQuery .serialize() function is useful mainly for GET requests. Even there having serialized data as request parameters is convenient for simple cases but can get quite ugly (see some of these "extreme" examples).

          Show
          Rossen Stoyanchev added a comment - Since POST and PUT tend to send data in the body of the request, the jQuery .serialize() function is useful mainly for GET requests. Even there having serialized data as request parameters is convenient for simple cases but can get quite ugly (see some of these "extreme" examples ).

            People

            • Assignee:
              Rossen Stoyanchev
              Reporter:
              Keith Donald
              Last updater:
              Rossen Stoyanchev
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 39 weeks ago