Search

Subscribe

Enter your email address to subscribe to this blog.

Recent Comments

Intro to Spring Security Core for Grails
Santosh said: Thanks much for putting up these screencasts. As the others here I'm a beginner and I've been having... [More]

Grails Spring Security Plugin - Logout postOnly setting
eriihine said: I still had some issues with this one. It seems that the href link is always generating a GET method... [More]

Intro to Spring Security Core for Grails
Dan Vega said: Just a heads up but I decided to write up a quick post on your question just in case it trips up any... [More]

Intro to Spring Security Core for Grails
eriihine said: Thanks for the clarification! [More]

Intro to Spring Security Core for Grails
Dan Vega said: First off thank you for the kind words. I plan on releasing more screencasts very soon. If you loo... [More]

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.

 
 

Creating and testing your first Grails Tag Library

I created a quick screencast to walk you through creating and testing your first tag library

BootstrapTagLib.groovy
BootstrapTagLibSpec.groovy

 
 

Getting Started with Gradle - Hans Dockter

I just wanted to take a second to share a screen cast that I came across. This was a presentation that Hans gave to a Java users group in October of 2012. I have listed the presentation description below but I just wanted to say that he is an absolutely amazing presenter. Very knowledgeable, dynamic and just fun to watch. Gradle can be a little overwhelming to some of us at first but I think he does a great job of showing you everything it can do it a short amount of time.

After sitting down with Marakana for an episode of Breaking Open, Hans Dockter, creator of the open source Gradle platform, and founder of Gradleware, headed over to the SFJava Usergroup to deliver this mammoth of a speech. Chock full of code and demos, Hans goes over everything that makes Gradle awesome: from serious build automation and organization, to Maven and Ant compatibility. If you're dealing with a jumbled mess of plugins and undocumented code, you probably want to check this presentation ou

 
 

Grails MySQL Boolean Gotcha

In the small app I am writing for fun I decided that it was time to switch over to a MySQL database. It was suprisingly easy to get Grails to talk to this new database. I won't go over every little step because Joe Rinehart already wrote up a nice guide for connecting grails to mysql. One comment I will make on that article and this was mentioned in the comments is that you can avoid downloading the mysql drivers and having to drop it in the lib folder. Go into grails-app/conf/BuildConfig.groovy & under dependencies uncomment the following line. Grails will then go out and download the dependency for you.

runtime 'mysql:mysql-connector-java:5.1.22'

So now that we have MySQL up and running we can take a look at the big GOTCHA I ran into tonight. I have a domain class (many actually) that define an active flag (boolean). If we take a look at my Brand domain you will see our boolean active property. This is meant as a flag to tell if the Brand should be active or not. After I was done with the domain model I fired up my application with some default data getting created in the Bootstrap. When I looked at the table structure and content this is what I saw.





Continue Reading >>

 
 

Groovy Strings - A couple of tips

One of the many differences from Java to Groovy is the way we can create strings. In Java a single quote is used to create a character literal. In Groovy we can use both single and double quotes to crate a string. We can test this by running the following code. This produces the following output.

java.lang.String
java.lang.String

You may also already know that we can use Groovy Strings to perform String interpolation. Using the ${} we can have the expression inside the brackets evaluated. One big thing to understand here now is that there is a different class for Groovy Strings and plain Strings. We can see the difference by running the following code. That produces the following output

java.lang.String
org.codehaus.groovy.runtime.GStringImpl
I wanted to point this out so one thing is made very clear here. Strings and Groovy Strings are not the same. Just because we can create a string with single or double quotes doesn't mean that we can do so with Groovy Strings. In fact if you replaced the example above with single quotes 'Hello ${str}' you would just have that string repeated back and no expression will be evaluated. Use double quotes when you are working with Groovy Strings. This also applies to multiline string """ vs '''

Finally you may already know this but haven't really thought about it. We are NOT just replacing a variable in our string, we are evaluating an expression. Remember that Strings are objects and objects have operations that we can perform on them. In the following code we are calling the toUpperCase method from the String class to turn the string World into WORLD. That produces the following output.

Hello WORLD!
Strings in Groovy are great and there is a lot more to learn about them but I thought I would share these 2 gotchas with you this evening.

 
 

More Entries