grails - 升级后出现Grails groovy.lang.MissingMethodException

标签 grails

在我的GSP文件中

<g:form controller="hello" action="createUser">
<g:select id="users"  class="required" name="users"  from="${hello.HelloController.userList()}" noSelection="['':'-Select user-']"/>

在我的HelloController中
class HelloController {

        ..
        def users= []
       ...
        def userList= {

                  return users;
        }

我得到的错误
groovy.lang.MissingMethodException
Message
No signature of method: static hello.HelloController.userList() is applicable for argument types: () values

我尝试仅使用from=${userList()}并将userList更改为static。所有这些都会带来更多错误。这在我在新计算机上设置新环境时执行grails升级之前一直有效

最佳答案

您需要在此处更改几件事。

一种,定义 Controller Action 的首选方法是方法而不是闭包。

class HelloController {
    def userList() {
        return users
    }
}

第二,您的 View 不应调用 Controller 方法。 Controller Action 应返回渲染 View 所需的模型。
class HelloController {
    def list() {
        return [userList: users]
    }
}

然后,在您的 View 中(即hello/list.gsp),您可以访问userList

关于grails - 升级后出现Grails groovy.lang.MissingMethodException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23688615/

相关文章:

google-chrome - 无法在 Google Chrome 中但在 IE10 中播放来自 Grails 网络应用程序的文件(音乐、照片等)

git - 如何 checkin 文件以使用 git 构建?

Grails 2.4 过滤器似乎不起作用

grails - 查找应用程序中的所有 Controller

grails - 将Grails域属性的defaultValue设置为Joda-Time Period.ZERO

grails - 不知道我是否有空白约束或动态脚手架问题

security - 集成测试 grails spring 安全插件?

Java/Grails - PrettyTime NLP 可以拆分非日期部分吗?

mysql - Grails/Groovy - 返回 Map 中的 MySQL 记录仅保留最后一条记录

grails - 如何为 Glassfish 生成grails jar组件