Issue Details (XML | Word | Printable)

Key: GRAILS-2348
Type: Bug Bug
Status: Closed Closed
Resolution: Duplicate
Priority: Minor Minor
Assignee: Graeme Rocher
Reporter: Rick Cromer
Votes: 1
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Grails

application/create throws java.lang.ClassCastException: Application cannot be cast to javax.servlet.ServletContext

Created: 01/Feb/08 11:22 AM   Updated: 10/Feb/09 09:10 AM
Component/s: Controllers, View technologies
Affects Version/s: 1.0
Fix Version/s: 1.1-RC1

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive testapp.zip (194 kB)

Environment: Running locally with the in-memory database and using the scaffold controller, Windows XP, 1.0 snapshot build 142, jdk 5.x


 Description  « Hide
I have a demo grails application that can be used to re-create this error. I have a controller name ApplicationController, and corresponding Application domain class.
I can view the list applications web page (no records shown), but I can't add applications.

To recreate this bug, just run rails run-app and click on the Applications link from the home page. Then click on New Application link, you will see the following error

Message: Application cannot be cast to javax.servlet.ServletContext
Caused by: Application cannot be cast to javax.servlet.ServletContext
Class: Unknown

java.lang.ClassCastException: Application cannot be cast to javax.servlet.ServletContext

at WEB_INF_grails_app_views_application_create_jsp.run(WEB_INF_grails_app_views_application_create_jsp:9)

I suspect that I'm using a reserved name for my controller causing a class name conflict. If this is the case, it would be nice to know what tablename/fieldnames we should not be using to avoid this and get an error message that tells us this.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Graeme Rocher added a comment - 01/Feb/08 12:05 PM
The bug is because there is a variable in the GSP binding called 'application' that is the ServletContext this gets overridden when you return the model from the controller [applicaton:Application.get(params.id)]

I wouldn't say its critical as changing the controller code would fix the problem


Rick Cromer added a comment - 01/Feb/08 12:05 PM
I have even a simpler way to re-create this problem, just create a new grails application, add a domain called Application and create a controller named Application and use the default scaffold. Then try to add an application and you will get this error.

Steven Olsen added a comment - 19/May/08 05:30 PM
I had the same error and it drove me insane, and embarrassed me while working on a demo GRAILS project in front of my boss. :\ That really sucked.

Graeme Rocher added a comment - 10/Feb/09 09:10 AM
This is already fixed, we have a set of reserved words. An error is printed to the console if you try to override these "application" is one of the reserved words