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

4

3 回答 3

0

这是整个代码吗?您可能会遇到调用list()in 的问题,dynamicList()因为它与操作匹配。换句话说,list()是 的简写list.call(),它将调用list闭包。

当然,发生了一些非常奇怪的事情,因为异常说它找不到类dynamiclist()上的方法MissingMethodException

你有一个可重复的例子吗?

于 2010-06-02T08:30:59.950 回答
0

您确定您的继承是正确的并且您已经运行 grails clean 等吗?您描述的情况应该可以正常工作。

于 2010-05-30T03:47:58.240 回答
0

我认为控制器是通过 grails 注入框架启动的,因此在这里使用奇怪的继承逻辑可能不是最好的方法。

尽管您可以使用组合而不是扩展基类。有一个功能可以让您轻松地将服务注入控制器,因此您可以按功能将服务分组到服务中。在此处输入链接描述

这是一个老问题,您可能会发现答案或技术有所发展。

自动注入适用于服务和控制器以及标签库。

于 2013-12-20T10:53:48.003 回答