Wednesday, 28 July 2010

Grails: Debugging GSPs: "errors at line [x]"

Debugging GSPs can be a right pain, especially with a heavily translated site: this often involves nesting g:messages inside virtually every other tag.

One of my annoyances was that the line numbers reported by the Grails parser were often wrong. "Error on line 430", it would say. "But my GSP only has 150 lines!" I shout back at my screen

I believe the problem is from nesting templates - when a GSP renders a template, that in turn renders a template, and so on - then the code grails generates is one file concatenated from each file that's been rendered.

So, how do you find where in your code things are going wrong? By appending ?showSource=true to your URL (or &showSource=true if you're passing in GET parameters). That's how.

This shows you Grails' generated file - I've found that the line numbers match, as you'd expect.

No comments: