title: Grails select tag results
body: <p>I'm trying to update a <code>hasMany</code> relationship through a form using data binding, but the data I get in my <code>params</code> doesn't seem correct.</p>
  
  <p>Domain class:</p>
  
  <pre><code>class CustomerSite {
  
  static hasMany = [dhrs:DeviceHistoryRecord];
  
  static mapping = {
      id generator:'sequence', params:[sequence:'cs_seq']
  }
      ...
  }
  </code></pre>
  
  <p>Edit view:</p>
  
  <pre><code>...
  &lt;g:select name="dhrs" id="dhrs" 
  from="${DeviceHistoryRecord.list()}"
  multiple="multiple"
  optionKey="id"
  value="${customerSiteInstance?.dhrs}"/&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>def update = {
      def customerSiteInstance = CustomerSite.get( params.id )
      if(customerSiteInstance) {
  
          customerSiteInstance.properties = params
  
          String flashMsg = new String();
  
          flash.message = "";
  
          if(!customerSiteInstance.hasErrors() &amp;&amp; customerSiteInstance.save()) {
              flash.message += "Customer Site ${customerSiteInstance.toString()} updated"
              redirect(action:show,id:customerSiteInstance.id)
          }
          else {
              flash.message = flashMsg
              render(view:'edit',model:[customerSiteInstance:customerSiteInstance])
          }
      }
      else {
          flash.message = "Customer Site not found with id ${params.id}"
          redirect(action:edit,id:params.id)
      }
  }
  </code></pre>
  
  <p>This gives me an error: </p>
  
  <blockquote>
    <p>Error 200: org.springframework.beans.NotReadablePropertyException: Invalid property 'currentDeviceData' of bean class [java.lang.String]: Bean property 'currentDeviceData' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?</p>
  </blockquote>
  
  <p>at this line in the controller code:</p>
  
  <pre><code>if(!customerSiteInstance.hasErrors() &amp;&amp; customerSiteInstance.save()) {
  </code></pre>
  
  <p>That doesn't make any sense to me, but I did some fooling with it (a lot, actually), and eventually figured out that the <code>g:select</code> is passing in a collection of indexes to params. </p>
  
  <p>The view outputs code that I think looks correct:</p>
  
  <pre><code>&lt;select name="dhrs" id="dhrs" multiple="multiple" &gt;
    &lt;option value="2421" &gt;801122&lt;/option&gt;
    &lt;option value="2422" &gt;801123&lt;/option&gt;
    ...
  </code></pre>
  
  <p>If I were to select items at index 0 and index 1 of the list, it's not passing in a set of "2421" &amp; "2422" like I'd expect.  It's passing in "0" &amp; "1".  To make matters worse, after I run that, when I go back to the edit page and run it again, this time selecting something at index 8, it's going to have "8"...but also the "0" and "1" from last time.</p>
  
  <p>Looking around here a bit, I found <a href="https://stackoverflow.com/questions/8476880/selecting-multiple-values-from-select-tag-grails">Selecting multiple values from select tag - Grails</a>, which has some other ideas, including making a change like this:</p>
  
  <pre><code>&lt;g:select name="dhrs.id" 
    from="${DeviceHistoryRecord.list()}" 
    multiple="multiple" 
    optionKey="id" 
    value="${customerSiteInstance?.dhrs*.id}"/&gt;
  </code></pre>
  
  <p>But that gave me a missing method error, although it did fix the issue of having indexes instead of actual values returned.</p>
  
  <p>Any ideas of what's going on here and how I can fix it?</p>
  
  <p>BTW, I'm running version 1.0.4 of Grails.  Yes, I'd love to upgrade it, but I can't.</p>
  
  <p>Thanks!</p>