Java Reference
In-Depth Information
Controllers
Grails controllers contain methods called actions that map to URLs. They either forward to
other resources, render outputs directly, or redirect to other URLs.
More important for the architecture discussion, however, is the map provided as the
return value of the action. The map contains two keys, castleInstanceList and
castleInstanceTotal . The former is associated with a list of 10 castles (or whatever
the max parameter evaluates to), and the latter gives their total number. That's fine, but it's
how those values are computed that's truly interesting. Grails adds both a list method
and a count method as static methods on the domain classes.
No Dao Classes
Instead of Data Access Objects, Grails uses Groovy metaprogramming to add static meth-
ods to the domain classes. This follows the Active Record [ 12 ] approach, which is unusual
in Java frameworks but very popular in Ruby.
12 From Martin Fowler's Patterns of Enterprise Application Architecture (Addison-Wesley Professional, 2002). See
http://en.wikipedia.org/wiki/Active_record for a brief summary.
According to the standard architecture, a controller is supposed to access DAO classes
through a service layer. In the static scaffolding there's no service layer. That's fine if the
application really islittle morethanaweb-drivendatabase, butingeneral applications need
more than that.
Services
Business logic in Grails should be placed in services, which are transactional, Spring-man-
aged beans that can be automatically injected into other artifacts.
This application does contain a service. It's the Geocoder , familiar from the Groovy
Baseball application. In the next listing it operates on Castle s.
 
Search WWH ::




Custom Search