Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables Grails1.3.6-对象字段似乎失去了价值_Variables_Grails - Fatal编程技术网

Variables Grails1.3.6-对象字段似乎失去了价值

Variables Grails1.3.6-对象字段似乎失去了价值,variables,grails,Variables,Grails,我是Grails的新手,使用的是Grails的一个古老版本(1.3.6/8)。我有一个对象,其中包含一些变量,这些变量不包含我分配给它们的内容 class NiftyController { try { SomeGrid someGrid = new SomeGrid() def selectedDate = params.specifiedDate ... someGrid.selectedDate = sele

我是Grails的新手,使用的是Grails的一个古老版本(1.3.6/8)。我有一个对象,其中包含一些变量,这些变量不包含我分配给它们的内容

class NiftyController {

    try
    {
        SomeGrid someGrid = new SomeGrid()
        def selectedDate = params.specifiedDate
        ...
        someGrid.selectedDate = selectedDate
        someGrid.longDate = Calendar.getInstance().getTimeInMillis()
        println someGrid.selectedDate // prints, say, 08/06/2012
        println someGrid.longDate // prints, say, 1302558890256
        ....
        doSomeWork(someGrid)
    }


    def doSomeWork = { SomeGrid someGrid ->
        println someGrid.selectedDate // prints '' (empty)
        println someGrid.longDate // prints 8 - the number for the current month.
    }
}
我完全是在挠头——我使用Java,这种类型的赋值变量数据丢失是新的,对我来说毫无意义。有人知道这里发生了什么吗?我猜这是Grails特有的某种可见性问题,但我无法解决


非常感谢您的帮助

如果
doSomeWork
本身不需要控制器操作,我会将其作为一个普通方法而不是闭包:

private doSomeWork(SomeGrid someGrid) {
  //...
}
作为一个闭包,Grails可能将
SomeGrid
参数视为一个命令对象,并试图直接从
params

将其数据绑定到“try”块是什么?它是否包含在某些行动/方法中?在打印someGrid.longDate和doSomeWork(someGrid)之间有什么区别吗?