Grails

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

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Duplicate
  • Affects Version/s: 1.0
  • Fix Version/s: 1.1-RC1
  • Labels:
    None
  • Environment:
    Running locally with the in-memory database and using the scaffold controller, Windows XP, 1.0 snapshot build 142, jdk 5.x

Description

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.

Activity

Hide
Graeme Rocher added a comment -

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

Show
Graeme Rocher added a comment - 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
Hide
Rick Cromer added a comment -

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.

Show
Rick Cromer added a comment - 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.
Hide
Steven Olsen added a comment -

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.

Show
Steven Olsen added a comment - 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.
Hide
Graeme Rocher added a comment -

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

Show
Graeme Rocher added a comment - 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

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: