title: Grails: Pre-select a g:select option in a table row using g:each
body: <p>I'm having an issue with preselecting an entry in a grails select drop down. I have a table and each row has a drop down.</p>
  
  <p>The rows in the table are defined by a g:each:</p>
  
  <pre><code>&lt;g:each in="${fooList}" status="i" var="fooInstance"&gt;
  </code></pre>
  
  <p>So this each row has fields of this object, lets just call it Foo!</p>
  
  <pre><code>String name
  String age
  Bar xyz
  </code></pre>
  
  <p>The problem comes in the last column. The object has within it another object (Bar xyz). I want to be able to change this Bar (which is a domain object) in the current Foo. But the Foo may already have a Bar in it when the page loads.</p>
  
  <p>How do I tie the select to the pre-populated sub-object? The select has within it the possible values of the sub object (All Bars currently available) but the binding isn't working!</p>
  
  <pre><code>&lt;td&gt;${fieldValue(bean: fooInstance, field: "name")}&lt;/td&gt; //this is fine
  
  &lt;td&gt;&lt;g:select from="${Bar.list()}" name="xyz" 
  optionValue="${fooInstance.xyz}" value="${fooInstance.xyz.id}" 
  optionKey="id" noSelection="['':'-Choose a Bar-']" /&gt;&lt;/td&gt;
  </code></pre>
  
  <p>Any ideas? Hope that's clear enough, let me know if you need any other info,</p>
  
  <p>Thanks,
  Tony</p>
  
  <p>By the way, the stack trace I get is:</p>
  
  <blockquote>
    <p>Caused by MissingMethodException: No signature of method: xxxxxxxxx.Bar.getAt() is applicable for argument types: (xxxxxxx.Bar) values: [aaablahblah]
    Possible solutions: getAt(java.lang.String), getAll(), getId(), getAll([Ljava.lang.Long;), getAll(java.util.List), get(java.io.Serializable)</p>
  </blockquote>