views:

409

answers:

3

I've tried with netbeans and eclipse, with no luck... (coudn't try IntelliJ idea)

I gave a quick look ant the code

http://kickjava.com/src/groovy/servlet/TemplateServlet.java.htm

and it gives me the impression that .gsp pages are translated to .groovy servlets (groovlets) in memory (I might be wrong)...

so perhaps it's not so easy to debug gsp as I though...

so, can anybody tell me how to do it?

pd: By debugging I mean things like browsing the code step-by-step, inspecting variables, adding watches, and all those sort of things, obviously. Not the (not so) good old printf approach...

+1  A: 

Most of the logic in your GSPs should be encapsulated in TagLibs, and you can debug them (with IntelliJ at least), just as easily as any other Groovy code.

If you do have a lot of scriptlet code in your GSPs (which you shouldn't), and you want to debug into it, you can't do much more than println. One other possibility is to view the source of the Groovy code generated for your GSP. This can be done by appending a showSource parameter to the URL, as described here.

Don
good point about the tag libs, had no idea they could be debugged...
opensas
+1  A: 

I use a hack: add a method to any controller, like static def debugme(def param) { def a = param }, and call it from gsp code: <% ThisController.debugme(this) %>, or <% ThisController.debugme(params) %>

(you do know you don't have to restart application after editing a controller or view, right?)

I also don't think that all the logic should be in taglibs: page-specific logic should be clearly visible in a controller or a view. We have most of the logic in controllers or domain classes.

Victor Sergienko
+1  A: 

Add a setting to Config.groovy and the generated gsp-files will be written to a directory: grails.views.gsp.keepgenerateddir='/some/existing/directory' (the target directory has to exists and be writable)

More information: http://jira.codehaus.org/browse/GRAILS-4422

It should be possible to debug the generated groovy code with a standard Java debugger. It was a long time ago when I did that (when I created the patch to grails) and I think I used jswat (http://code.google.com/p/jswat/) to debug gsps. I couldn't get eclipse to find the source files, but that's probably working in Spring Tool Suite Eclipse nowadays. You have to debug groovy code step-by-step/step-into and use filters, otherwise you might lose the step point (because of closures?). That's already another story...

FlareCoder