Enter your email address to subscribe to this blog.

Recent Comments

Grails Spring Security Plugin - Logout postOnly setting
Adam said: I believe remoteLink should work [More]

Grails Spring Security Plugin - Logout postOnly setting
Jan said: Hello your solution seems to work. - But why is a POST logout needed? I was actually thinking about ... [More]

jQuery Select Example
mysql services said: nice commands to work and apply in projects really helpful [More]

ColdFusion cfinvokeargument bug
Paul Rowe said: I understand the frustration with this. Unfortunately, I think this is one of the "affordances&... [More]

ColdFusion cfinvokeargument bug
Adam Cameron said: @Henry is correct. This is standard behaviour in all CFML tags as far as I am aware. It's counter-in... [More]

ColdFusion cfinvokeargument bug

A coworker and I were debugging some old code yesterday and couldn't believe what we came across. Say you have a component and and in a method for whatever reason you were using cfinvoke to call another method. In this case we have a variable called foo.result set to true. When this is passed to the method doSomething else what would you expect the value to be?

If you said true you and I are on the same page, but that isn't the case. It turns out if you leaves the quotes off it will not try and evaluate the variable and just accepts it as a string so the result is...

That's right, it treats it as a string. This to me seems like a bug as I would expect it to evaluate the variable there. An easy fix for this is to wrap it in ## with or without the quotes.


Gravatars on a Grails Application

Building out my new site I needed the ability to show a Gravatar in the comments. I know there are usually plugins out there but I there are a lot of things I am going to do on my own just so I have an excuse to blog about them. First off visit the Gravatar docs to get an idea of how to request an image. This is what the finished product is going to look like.

The most basic image request URL looks like this:

where HASH is replaced with the calculated hash for the specific email address you are requesting. For example, here is my base URL:

If you look at the docs there are ways to customize the size and default image if an account is not found. There are a couple different approaches we can take but this is the route I decided to go. Since a comment is just going to be inserted why not store the email hash in the db. We have an easy way of doing this with GORM events. On insert I am going to get the MD5hash of the email address and store it.

That is really all there is to it. Now we can call ${comment.emailHash} and grab that value right from the db. Here is what the final comments template looks like.


Grails: Generating links in your domain class

I am working on coverting this site over to a grails applicaiton. While there are some good plugins out there I could of taken advantage of I decided to use this as a learning experience and write a ton of it from scratch.

For the blog post itself we have some unique URLs that look like this

This converts to /blog/year/month/day/slug. So first thing I needed to was setup a url mapping for this path. I also put some constraints on the parameters so we get exactly what we are looking for.

Continue Reading >>


Grails views: Controller and Action name

In a project I am working on i have a navigation bar and depending on what "page" I am on I need to have the class set as active.

If you look at the web layer documentation you will see that within the scope of a GSP there are a number of pre-defined variables, including:

There are also two variables that are available that will help us out with our little problem. These variables will give us the current controller and action.

  • controllerName
  • actionName
Now in our navigation bar code we can do a simple check to see if this menu item should have the active class.

In my case I actually have a home controller. When you fire up a default grails application you won't. This is perfectly fine and thankfully the controllerName variable will return null if this is the case. So we can modify our code to test for that.


Grails Spring Security Plugin - Logout postOnly setting

I had a question come in about a setting in Spring Security so I thought I would take a quick minute and explain it in case anyone else also has the same question. There is a setting

'grails.plugin.springsecurity.logout.postOnly = true'
that is true by default. If you look at the LogoutController's index action this make a little more sense.

All this is saying is that to Logout we must have that request made in the form of a post. An easy way to do that is create a link to the logout controller (remember index is our default action).

If you try and just visit the URL http://localhost:8080/{your_context}/logout you can tell by the code that this should throw a 405 error, and it does.


More Entries