title: Populate Grails g:select from function
body: <p>Trying to populate a g:select from a function in my controller, is it possible?</p>
  
  <p>Currently we have this:</p>
  
  <pre><code>def run(Long id) {
  
      def reportInstance = Report.get(id)
  
      def listPromptValues = populatePrompts(reportInstance)*.values()
  
      if (!reportInstance) {
          flash.message = message(code: 'default.not.found.message', args: [message(code: 'report.label', default: 'Report'), id])            
          return
      }
      [reportInstance: reportInstance, listPromptValues: listPromptValues]
  }
  
  def populatePrompts(Report rp){
      //for each prompt in the report, go out and get it's values
      rp.prompts.collectMany {
          reportService.listDatatypeValues(it.datatype)
      }
  
  }
  </code></pre>
  
  <p>And then the g:select in question is</p>
  
  <pre><code>&lt;li class="fieldcontain"&gt;
                  &lt;g:each var="prompt" in="${reportInstance.prompts}"&gt;
                      &lt;span id="prompts-label" class="property-label"&gt;
                          &lt;g:message code="report.prompts.label" default="${prompt.name}:" /&gt;
                      &lt;/span&gt;
                      &lt;g:if test="${prompt.datatype.type == 'DropDown'}"&gt;                         
                          &lt;g:select id="prompt.name" from="${listPromptValues}" name="prompt.name" value="" noSelection="['':'']"/&gt;
                          &lt;br&gt;                            
                      &lt;/g:if&gt;
                  &lt;/g:each&gt;
              &lt;/li&gt;
  </code></pre>
  
  <p>Which works just fine if there is only one prompt, however we need to be able to call the populatePrompt function directly from the gsp view if there is more than one prompt in the loop, possible sending the reportId and then getting back the listPromptValues. I can't seem to get the onChange(remoteFunction...) to work properly and am coming up empty handed in searching the vast Google webs.</p>
  
  <p>Something like how createLink works</p>
  
  <pre><code>${createLink(controller:'report', action:'runReport', id:"${reportInstance.id}")}
  </code></pre>
  
  <p>But instead of createLink, it would be the from attribute of the select tag, something like:</p>
  
  <pre><code>&lt;g:select id="prompt.name" from="{(controller:'report',action:'populatePrompt', id:"${reportInstance.id}")}" name="prompt.name" value="" noSelection="['':'']"/&gt;
  </code></pre>
  
  <p>Any ideas, or direction to go?</p>