Grails: Links from my first week with Grails

Posted on October 11th, 2008 by Reiner.
Categories: Grails, English, Computers.

Never before in my life I had the opportunity to learn a new technology and put it into productive use within just a couple of days. Grails will change is changing the Java and framework landscape right now. Using Grails, within less than 3 weeks, an application has been developed that accepts NFC-scans from mobile devices (i.e. Nokia 6131 NFC), sends notifications by email and by SMS, and renders a live view of scans as well. None of the staff involved had any previous experience with Grails whatsoever (I started implementing the domain classes and services, a colleague of mine then took over to implement the GUI while I was on vacation on the Canary Islands). Our work was targeted towards NetBeans, GlassFish and PostgreSQL.

Listed here are the links that helped us jump on the track to wealth, glory and wisdom :-)

1-2-3

Links

Pet stores, sort of:

The web service side:

Still more advanced:

Slightly off topic:

Tiddlers:

Deutsche Ecke (German corner, don’t hold your breath yet):

Watch out

2 comments.

Grails: How to log within static methods

Posted on August 20th, 2008 by Reiner.
Categories: Grails, English.

Grails injects a log object for each artifact, but these loggers are not accessible within static methods.

Here’s a quick-and-dirty code snippet sample that demonstrates how to log from a static method within domain class Account. The trick is to get the Logger by invoking org.apache.commons.logging.LogFactory.getLog(this):

import org.apache.commons.logging.LogFactory

static Account createOrFindByImei(String imei)
{
    Account result = Account.findByImei(imei)
    return result ? result  :
    saved(new Account(
            imei:imei,
            email:Login.getCurrentLogin().email,
            name:"* New Account ($imei) created at " + new Date()))
}

private static Account saved(Account account)
{
    if(account.save())
    {
        return account
    }
    LogFactory.getLog(this)
      .error("!saved: $account.errors", new Throwable("*STACKTRACE*"))
}

4 comments.