Posts Tagged ‘bugs’

Grails, The Good and The Bad

Monday, September 21st, 2009 by admin

As I’ve mentioned here before we’ve been using Grails to build the web front-end for Sierra as well as the Sierra REST API.  This week has provided a couple of great examples of the joys, and pains, of using open source software.  Let me start by saying that using Grails is mostly all joy, and not much pain.

While working on the administration console for Sierra this week I ran into a case where I needed to paginate a set of results.  Having built web applications for years now I have some pretty tried and true methods for doing this.  However, in the past while using other frameworks these methods have involved me writing a decent chunk of code.  With Grails that chunk of code is no longer needed.  Or, a least I don’t have to write it.  Let me show you a simple example.  Let’s say we have a “show” method on a UsersController that either fetches a single user (if we pass in an id), or returns a list of all users.  It might look something like this:

def show = {
    if (params.id && User.exists(params.id.toLong())) {
        def user = User.get(params.id)
        [user: user]
    } else {
        // default max num for the page to 10 if not specified
        if (!params.max) {
            params.max = 10
        }
        render view: "list", model: [userList: User.list(params)]
    }
}

Notice the call to “User.list(params)”.  This is passing in the URL parameter coming from the client into call to fetch the users.  If those parameters contain paging information then the list() method will fetch the proper subset of users.  I didn’t have to code the list() method.  Grails just gives it to me.
(more…)

Tags: , , ,
Posted in SaffronSierra | 1 Comment »