Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to debug a gsp page? (no grails, just gsp)

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...

like image 388
opensas Avatar asked Oct 30 '09 11:10

opensas


3 Answers

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.

like image 157
Dónal Avatar answered Sep 20 '22 02:09

Dónal


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.

like image 35
Victor Sergienko Avatar answered Sep 21 '22 02:09

Victor Sergienko


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...

like image 35
Lari Hotari Avatar answered Sep 22 '22 02:09

Lari Hotari