Another Method for Admin screens with Grails

I came from a background of making sites with Django and after I starting going head-first into Grails, one of the things I missed was a really good and easy to make an admin section. You know — something that “just works” to do some basic CRUD. I know that there is the scaffolding plugin but the problem with that is that it’s not always robust and it’s not easily configurable. I want my admin pages to be look nice as well as being robust.

A little while ago I bumped into the admin-interface plugin, which pretty much does everything that I had hoped for. There is a bit of configuration but it’s not much more than what you had to do in Django. I have a very simple github project for you to play with.

If you look at the bottom of the Config.groovy you will see some simple configurations:

The AuthorAdmin and BookAdmin are little descriptor files that say what fields should appear to be and what order. I found that admin-interface really isn’t that smart — that the fields aren’t listed in any sensible order so I think that file is quite necessary. It’s not even smart enough to remove dateCreated and lastUpdate which Scaffolding does just fine! My sample Author file looked like this:

Admin page with random order

You just have to add the field to the list. This isn’t quite the magic I was hoping for, but it’s only small change, as oppose to generating GSPs or editing them to put in a field.

It’s not like these files are complicated. See below for the Author’s admin file:

And then admin page looks immediately better:

Much better!

I didn’t do it in my example but it can use Spring Security to define what role has access to the Admin section. You can also define the URL and put different domains in logical groups. These are things that this plugin does better than Scaffolding.

I think the admin-interface plugin can easily replace the scaffolding plugin and have happier users too.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*