views:

209

answers:

2

I wrote a base class to help build my controllers more quickly and to remove duplication. It provides some helper methods, default actions and some meta programming to make these things easier to build.

One of those methods in the base class is like this:

def dynamicList(Class clazz) {
    def model = new LinkedHashMap()
    model[getMapString(clazz) + "s"] = list(clazz)
    model[getMapString(clazz) + "sTotal"] = count(clazz)

    model
}

The action that calls it, also in the base class, is this:

def list = {
    dynamicList(clazz)
}

Unfortunately, when I go to list action in the controller subclass that inherits the base class when my application is deployed, I get this exception:

groovy.lang.MissingMethodException: No signature of method: groovy.lang.MissingMethodException.dynamicList() is applicable for argument types: (java.lang.Class) values: [class project
.user.User]

    at project.user.UserController$_closure1.doCall(UserController.groovy:18)

    at project.user.UserController$_closure1.doCall(UserController.groovy)

    at java.lang.Thread.run(Thread.java:619)

How can I hit grails over the head and just tell it do what I want it to do? My controller unit tests run just fine, so grails' run-time is totally at fault :/

Ken

A: 

Are you sure your inheritance is all proper and you've run grails clean etc.? The situation you've described should work just fine.

John Stoneham
yep, i'm sure... I am sick of grails. It is one thing after the other with it. I just want to develop software, not know every exception to the rule and know a list of things that I can't do before I do them. It's actually not productive at all. Gorm is great. The gsps are okay. The controllers are horrible. Groovy is no scala either. Dynamic languages are just bad. Thanks for answering, but I am just disgusted with grails.
egervari
I don't know precisely what you're doing, but I don't understand how your difficulties with controllers have much to do with dynamic versus static languages. Sorry you feel that way about Grails, but I wish you would express some more concrete concerns that someone could help you with.
John Stoneham
The dynamic vs. static has nothing to do with controllers - that's a framework thing, but the refactoring and code completion support when testing controllers is a big pain. You really have to know all the dynamic stuff to be able to test a controller. I can't just type "." and have my IDE tell me that it's renderArgs.view or redirectArgs.action. Not being able to "guess" with IDE support is a really, really bad thing. I don't want to have to learn every little detail. The IDE is supposed to help speed this learning curve up. Dynamic languages are terrible for this.
egervari
It's a trade-off. Yes, you have to know the API and read the documentation. You're trading dynamic productivity, readability, and maintainability versus help with boilerplate, basically.Your beef's with dynamic languages then. Stay away from Rails too.
John Stoneham
A: 

Is that the whole of the code? You're likely to run into problems with the call to list() in dynamicList() because it matches the action. In other words, list() is shorthand for list.call(), which will invoke the list closure.

Certainly something very strange is happening because the exception is saying it can't find the dynamiclist() method on the MissingMethodException class.

Do you have a reproducible example?

Peter Ledbrook