Skip to content

Grails’ chainModel

A question came up on the Grails mailing list recently regarding how to pass model data from one action to another.

The solution is to make use of chain() and the chainModel map. As the doco says:

This dynamic property only exists in actions following the call to the chain method…

Here’s a trivial Grails controller class that illustrates How To Do It:

package bob

class TestController {
  def index = {
    chain(action:'doIt', model:[data:new Data(when:new Date(), what:"Hello, world")])
  }

  def doIt = {
    render chainModel.data.what
  }
}

class Data {
  Date when
  String what
}

I’ve used chain() several times before, but it’s been good to refresh my understanding of chainModel.

The doco is here and here.

Tags:

Grails/Ehcache Tip

Another one to remember.

Ehcache (used by default in the later releases of Grails) has an update checker that apparently is on by default.

Innocuous but a bit of a pain: consider the potential adverse affects for a production box.

If that doesn’t make you nervous…consider trying to investigate this [putatively unexplained] behaviour during a load testing session conducted in front of your [also putatively, nervous] manager (been there, wasn’t pretty: “What’s this spike? What’s this spike? What’s this spike.”)…

If that wasn’t enough to get you sweating, well: according to Sven Lange in A web geek’s blog:

UpdateChecker is not only looking for updates. In addition it also submits information about the applications environment to Terracotta by default. And this sucks in my opinion.

It sucks in my opinion, too. This is why I want to keep this link hanging around.

(Found via the excellent Groovyblogs.)

Tags:

Senator Conroy Must Go!

(OK…this is my opinion, you’re free to disagree…I assume. For now.).

A graphic illustration that Australia’s Sen. Conroy doesn’t subscribe to (notice I don’t say “doesn’t understand”…he understands it well enough to reject it, I am sure…) the idea of free speech and democratic discussion:

The front page of Communications Minister Stephen Conroy’s official website displays a list of topics connected to his portfolio, along with links to more information about each one.

All the usual topics are there – cyber safety, the national broadband network, broadcasters ABC and SBS, digital television and so on.

All except one.

It was revealed today a script within the minister’s homepage deliberately removes references to internet filtering from the list.

In the function that creates the list, or “tag cloud”, there is a condition that if the words “ISP filtering” appear they should be skipped and not displayed.

Ridiculous…deliberately hiding a major (not un-concidentially really controversial) part of his portfolio to make it hard for interested parties to find out what he is doing.

Seriously: this guy is not fit to be a member of the nation’s governing body. I’ve said it before: Senator Steven Conroy should go. And soon.

Here’s the news.com.au source: Conroy’s website removes references to filter.

(Again…my opinion, YMMV).

Tags:

Video Piracy For Dummies

Saw this over on overclockers.com.au.

4

There is definitielysomething wrong (with the product, please note) when the ‘pirated’ version of a product is actually better than the real thing.

Tags:

The Old (Groovy) Switch-eroo Again…

Recently, I had the little task of looking at a string and deciding what to do based on the various values of an embedded prefix field.

I had to ask around a bit (thanks Paul!) to get the solution to my liking, but here’s yet another example of my favourite Groovy construct, the switch statement:

def days = [
  "Monday:I could wait till Tuesday",
  "Tuesday:must make up my mind",
  "Wednesday:would be fine",
  "Thursday:she's on my mind",
  "Friday:give me time",
  "Saturday:I could wait",
  "Sunday:would be too late"
]

final MON = 'Monday:'
final TUE = 'Tuesday:'
final WED = 'Wednesday:'
final THU = 'Thursday:'
final FRI = 'Friday:'
final SAT = 'Saturday:'
final SUN = 'Sunday:'

days.each { value ->
  switch(value) {
    case ~/^${MON}.*$/:
      println "$MON: ${value - MON}"
      break
    case ~/^${TUE}.*$/:
      println "$TUE: ${value - TUE}"
      break
    case ~/^${WED}.*$/:
      println "$WED: ${value - WED}"
      break
    case ~/^${THU}.*$/:
      println "$THU: ${value - THU}"
      break
    case ~/^${FRI}.*$/:
      println "$FRI: ${value - FRI}"
      break
    case ~/^${SAT}.*$/:
      println "$SAT: ${value - SAT}"
      break
    case ~/^${SUN}.*$/:
      println "$SUN: ${value - SUN}"
      break
  }
}

I know it’s a very contrived example, but take a look at the case ‘labels’: regular expressions that reference properties found elsewhere in the code. Neat-o!

Apologies to Sting (did you get the song?)!

Tags:

It’s A Two-Way Street

Just because I keep the comment facility turned off on this site doesn’t mean that I don’t really appreciate comments (bouquets or brickbats..all feedback is good) so please: if you have something you want to get off your chest, send me an old-fashioned email:

What prompted this? I just got a nice comment from Daniel saying “enjoying your website a lot. thought you’d like to know :-)”

I do like to know! Thanks Daniel.

Happy (Lunar) New Year!

It’s the year of the Tiger.

I hope you manage to achieve the same degree of satisfaction in your life as my little tiger has achieved in hers:

Furball-Pot

GroovyMag February 2010: Another Article By Yours Truly

Another GroovyMag USD$4.99 blockbuster.

This time taking a look at the combination of Grails, Griffon and a REST-like interaction style. It’s all Good Stuff.

gm16_400

Worth every cent.

Tags: , ,

Copy Image From URL To File

Just saving this away for a rainy day…something I concocted in response to a question on the Groovy mailing list:

new File("local.gif").withOutputStream { os ->
  new URL("remote.gif").withInputStream { is ->
    os << is
  }
}

The important thing to note here is the way the streams are carefully ’scoped’ and maintained so that no leaks can occur even if exceptions or other sticky situations arise.

Tags:

StarUML

A while back I mentioned the Violet UML editor. My mate Alex from Lexecorp pointed out that StarUML is another freebie:

StarUML is an open source project to develop fast, flexible, extensible, featureful, and freely-available UML/MDA platform running on Win32 platform. The goal of the StarUML project is to build a software modeling tool and also platform that is a compelling replacement of commercial UML tools such as Rational Rose, Together and so on.

It looks slightly out of date, but is still worth remembering.

Tags:

Java Enterprise Edition, JEE, JavaServer Pages, JSP, Tag Libraries, Servlets, Enterprise Java Beans, EJB, Java Messaging Service JMS, BEA Weblogic, JBoss, Application Servers, Spring Framework, Groovy, Grails, Griffon, Seam, Open Source, Service Oriented Architectures, SOA, Java 2 Standard Edition, J2SE