Reputation: 1479
A Grails application has a lot of auto-generated (from standard Grails 2.3.0 scaffolding) code using the new RESTful "respond" feature. For example, the index methods generally look like this:
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
respond Alpha.list(params), model:[alphaInstanceCount: Alpha.count()]
}
This works completely fine when the application is run as "grails run-app" however fails when the application is packaged as a .war and launched that way inside a non-embedded servlet container.
It works for the first controller/view combination used, but for subsequent ones uses the view folder of the first view rendered. E.g., if we try /alpha/index
first, and then afterwards /beta/index
then the /alpha/index
will work fine, but /beta/index
will use /alpha/index.gsp
for rendering (instead of the expected /beta/index.gsp
).
If, however, I change the method to:
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
render(view: 'index', model:[alphaInstanceList: Alpha.list(params), alphaInstanceCount: Alpha.count()])
}
then it works fine in both deployment options.
I added some debug code to some of the .gsp-s to output ${this.getGroovyPageFileName()}
, ${controllerName}
and ${actionName}
.
That shows that while the controller and action names are always the expected ones, the view used on views rendered after the first one remains the view used on the first one.
For example, the initial invocation for /alpha/index
has controller as alpha
, action as index
, and view as /WEB-INF/grails-app/views/alpha/index.gsp
, however the consequent invocation of /beta/index
has controller as beta
, view as index
, but view as /WEB-INF/grails-app/views/alpha/index.gsp
(note the wrong "alpha" here). Consequent invocations of alpha
remain fine.
If we had started with beta, and then moved to alpha, it would have been the other way around (beta
is fine, alpha
is broken).
I tried running it unders JPDA but while my IDE appears to be connecting it is not actually hitting any breakpoints (probably unrelated issue).
I'm using Grails 2.3.0, JDK 1.6, and Tomcat7.
There is nothing bad that I can see in the logs.
Any ideas what the issue may be, or even just how to approach debugging it?
http://goo.gl/aFKYYb <-- grails app
http://goo.gl/aDP6Lx <-- .war file
Upvotes: 2
Views: 2238
Reputation: 1479
Possible Grails defect (although they cannot reproduce):
http://jira.grails.org/browse/GRAILS-10614
I did a "install-templates" and am modifying the scaffolding templates as a work-around.
Edit - yes, confirmed; I forgot to update this response but upgrade to 2.3.1 solves the issue, as per the defect linked.
Upvotes: 1
Reputation: 3922
Upgrading to Grails 2.3.1 fixed this problem for me. (Reading the defect you posted pointed me in the right direction - thanks.)
Note that you will also have to upgrade your hibernate plugin to version 3.6.10.2, or you will get an error message similar to "Method on class [] was used outside of a Grails application."
Upvotes: 1