4

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

egervari
  • 22,372
  • 32
  • 121
  • 175

3 Answers3

0

I think Controllers are initiated via grails injection framework, so it may not be the best way to use strange inheritance logic here.

Although you can use composition instead of extending a base class. There is a feature which allows you to inject services easily into controllers, so you can group by functionality into Services. enter link description here

This is an old question, you may found the answer or technology evolved a bit.

Automatic injection works for Services and Controllers and tag libraries.

kisp
  • 6,402
  • 3
  • 21
  • 19
0

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
  • 2,485
  • 19
  • 10
  • 1
    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 May 30 '10 at 06:06
  • 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 May 31 '10 at 01:41
  • 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 May 31 '10 at 21:31
  • 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 Jun 04 '10 at 03:51
  • @ John Stoneham - I'm confused at what the trade-off is. With the dynamic language you get less productivity (since you have to know the API and read the documentation like you said), less readability (same thing, just reading the code isn't enough, you have to know how everything works underneath too), and less maintainability (mostly due to the lack of refactor support). That much I agree with. But then you also get less help with boilerplate type stuff since the IDE cannot autocomplete stuff for you. So what are the upsides? – Steven Byks Jun 24 '16 at 19:11
0

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
  • 4,302
  • 1
  • 21
  • 18