Grails
  1. Grails
  2. GRAILS-9895 Improve Data Binding
  3. GRAILS-8346

Grails parameter binding to a hasMany relationship fails when not using a multi-select list

    Details

      Description

      When creating an object that has a hasMany property, this propery will only be set using a "g:select" tag with "multiple" attribute set to true. Grails should not discriminate which DOM object allows binding to hasMany relationships. If a list of id's are sent as params to a controller and the corresponding domain object has a field that is a Collection, the binding should occur no matter if the list was sent from a multi-select box or a custom tag that also sends a list of id's.

      Background: I wrote a custom tag for multi-selection using checkboxes instead of a multi-select list (from a UI perspective, it only makes more sense). When submitting, I notice that the corresponding Set in my domain object is always null. When I change from my custom tag to "g:select" w/ "multiple" set to true, the corresponding Set in my domain has all the correct values. Both my tag and the g:select tab send the same list, but the only noticeable differences are
      1) g:select sends a multiple flag and my checkboxes cannot do that
      2) g:select does not send hidden fields, checkboxes send hidden fields, and the hidden fields are not populated (seperate bug??)

        Activity

        Hide
        Michael Hatch added a comment - - edited

        binding success when using g:select w/ multiple

        <org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap@dd83d83 request=org.apache.catalina.core.ApplicationHttpRequest@72f106b0 nestedDateMap=[:] wrappedMap=[lastName:, enabled:on, location.id:1, location:[id:1], approver.id:null, approver:[id:null], locale:null, _outOfOffice:, create:Create, password:, username:, password2:, email:, roles:[1, 2, 3], _enabled:, firstName:, action:save, controller:agent]>
        <customerrelationsdesk.Agent@3914c2fe username= password= firstName= lastName= email=null locale=null lastPasswordChange=null approver=null location=location 1 enabled=true outOfOffice=false id=null version=null roles=[admin, temp, readonly] agencies=null approvals=null>

        binding fails when using custom checkBoxList

        <org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap@39e97abb request=org.apache.catalina.core.ApplicationHttpRequest@42fb636b nestedDateMap=[:] wrappedMap=[lastName:, enabled:on, location.id:1, location:[id:1], approver.id:null, approver:[id:null], locale:null, _outOfOffice:, password:, create:Create, username:j, password2:, email:, roles:[1, 2, 3], _roles:[, , ], _enabled:, firstName:, action:save, controller:agent]>
        <customerrelationsdesk.Agent@4aa53726 username=j password= firstName= lastName= email=null locale=null lastPasswordChange=null approver=null location=location 1 enabled=true outOfOffice=false id=null version=null roles=null agencies=null approvals=null>

        Show
        Michael Hatch added a comment - - edited binding success when using g:select w/ multiple <org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap@dd83d83 request=org.apache.catalina.core.ApplicationHttpRequest@72f106b0 nestedDateMap= [:] wrappedMap=[lastName:, enabled:on, location.id:1, location: [id:1] , approver.id:null, approver: [id:null] , locale:null, _outOfOffice:, create:Create, password:, username:, password2:, email:, roles: [1, 2, 3] , _enabled:, firstName:, action:save, controller:agent]> <customerrelationsdesk.Agent@3914c2fe username= password= firstName= lastName= email=null locale=null lastPasswordChange=null approver=null location=location 1 enabled=true outOfOffice=false id=null version=null roles= [admin, temp, readonly] agencies=null approvals=null> binding fails when using custom checkBoxList <org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap@39e97abb request=org.apache.catalina.core.ApplicationHttpRequest@42fb636b nestedDateMap= [:] wrappedMap=[lastName:, enabled:on, location.id:1, location: [id:1] , approver.id:null, approver: [id:null] , locale:null, _outOfOffice:, password:, create:Create, username:j, password2:, email:, roles: [1, 2, 3] , _roles: [, , ] , _enabled:, firstName:, action:save, controller:agent]> <customerrelationsdesk.Agent@4aa53726 username=j password= firstName= lastName= email=null locale=null lastPasswordChange=null approver=null location=location 1 enabled=true outOfOffice=false id=null version=null roles=null agencies=null approvals=null>
        Hide
        Trygve Amundsen added a comment -

        Still a bug in 2.0.0.
        Multiple <g:checkBox name="foos"> creates two set of fields, 'foos' and '_foos', but <g:select name="foos" multiple="true"> creates 'foos' only.

        Workaround: remove '_foos' first in controller method: params.remove('_foos')

        Show
        Trygve Amundsen added a comment - Still a bug in 2.0.0. Multiple <g:checkBox name="foos"> creates two set of fields, 'foos' and '_foos', but <g:select name="foos" multiple="true"> creates 'foos' only. Workaround: remove '_foos' first in controller method: params.remove('_foos')
        Hide
        Michael Hatch added a comment -

        the '_foos' is the hidden field, correct? so the true nature of the bug is just that the hidden checkbox fields are not properly populated?
        Thanks for the update.

        Show
        Michael Hatch added a comment - the '_foos' is the hidden field, correct? so the true nature of the bug is just that the hidden checkbox fields are not properly populated? Thanks for the update.
        Hide
        Jeff Scott Brown added a comment -

        If someone would attach a simple app which demonstrates this problem, we will get it resolved for Grails 2.3. Thanks for any help.

        Show
        Jeff Scott Brown added a comment - If someone would attach a simple app which demonstrates this problem, we will get it resolved for Grails 2.3. Thanks for any help.

          People

          • Assignee:
            Jeff Scott Brown
            Reporter:
            Michael Hatch
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development