Java Reference
In-Depth Information
The Quest application provides a nice demonstration of the process involved. Suppose
I want the map to appear on the list.gsp page associated with the castles. Grails maps
the URL
http://<host>:<port>/holygrails/castle/list
to the list action in the
CastleCon-
troller
class. The last expression in that action is a map (a Groovy one rather than a
Google one), so Grails automatically adds the entries to the HTTP request and forwards to
the list.gsp page.
The goal, therefore, is to add the information needed by the map to the proper controller
action. As usual, the data should come from a service, and I already have the
Geocoder-
Service
available. The next listing shows the additional methods.
Listing 10.20. Methods added to the
GeocoderService
to support the mapping plugin
The
list
action in the
CastleController
is already returning a list of castles and the
total count, which are used to display them in a table. I might as well use the same action
to return the columns and data for the map.
The revised
list
action in
CastleController
looks like this:
def list() {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
[castleInstanceList: Castle.list(params),
castleInstanceTotal: Castle.count(),
mapColumns:geocoderService.columns, mapData:geocoderService.markers]
}
The following listing shows the additions made to the view, list.gsp, in order to display a
map of castles.