Java Reference
In-Depth Information
longitude()
}
}
The hasMany variable in Castle indicates that the Knight table will have a foreign
key to the Castle table.
In a trivial Grails demonstration, all the associated controllers would be scaffolded. In
Grails, that means they have a single property, called scaffold , as shown:
class QuestController {
static scaffold = Quest
}
The scaffold term tells Grails to dynamically (that is, at runtime) generate views to
list , show , edit , update , and delete a quest. The code for each of those actions is
produced at runtime, so it's not visible here. Eventually, however, I need to customize the
controllers and views, so I need to generate the static versions.
A portion of the Castle controller is shown in the next listing.
Listing 10.16. The static Castle controller class
class CastleController {
...
def list(Integer max) {
params.max = Math.min(max ?: 10, 100)
[castleInstanceList: Castle.list(params),
castleInstanceTotal: Castle.count()]
}
...}
The list action checks to see if the params map already contains a key called max . If
so it's converted to an integer and reset to the minimum of the provided value and 100. If
the parameter doesn't exist, then 10 is used as the max . Starting in Grails 2.0, request para-
meters can be used as arguments to controller actions, and type conversions will be done
automatically.
Search WWH ::




Custom Search