title: accessing class fields from GSP in Grails
body: <p>How can I access fields of classes from a GSP in Grails? For instance, the following:</p>
  
  <pre><code>geocoder.geocode({
        'address': 'london'
     }, 
  </code></pre>
  
  <p>I need to get the address programmatically after being inserted by the user. Something as the following:</p>
  
  <pre><code>geocoder.geocode({
        'address': ${search.city}
     }, 
  </code></pre>
  
  <p>where search is the class and city is the field.
  Is there a way to do this?
  Thanks</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I tried this:
  In the controller:</p>
  
  <pre><code>def map = {
      def searchInstance = Search.get(1)
      [locationList : Location.list(), search:searchInstance]
  }
  </code></pre>
  
  <p>In the view:</p>
  
  <pre><code>function initialize() {
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({
        'address': ${search.city}
     }, 
     function(results, status) {
        if(status == google.maps.GeocoderStatus.OK) {
  
            var myMapOptions = {
                    zoom: 8,
                    center: results[0].geometry.location,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                  };
  
                  map = new google.maps.Map(document.getElementById("map_canvas"),
                      myMapOptions);
  
                  &lt;g:each in="${locationList}" status="i" var="location"&gt;     
                  var point${location.id} = new google.maps.LatLng(${location.lat}, ${location.lng});
                  var myMarkerOptions${location.id} = {
                        position: point${location.id}, 
                        map: map
                       };
                  if(map.getCenter().distanceFrom(point${location.id}) &lt; 500000)
                      var marker${location.id} = new google.maps.Marker(myMarkerOptions${location.id});   
              &lt;/g:each&gt;
  
        }
     });
  </code></pre>
  
  <p>}</p>
  
  <p>I can access from the view the Location list returned by the map closure, but I can not access the search instance. 
  Any ideas?</p>