简体   繁体   English

呈现视图,但gsp中没有对象

[英]Rendering view, but no object in gsp

I try to render a view, which works fine, but it doesn't seem to get the model object I pass along to it. 我尝试渲染一个视图,该视图工作正常,但似乎无法获得传递给它的模型对象。 I can't figure out the reason, as this should be very straightforward according to all manuals and examples. 我不知道原因,因为根据所有手册和示例,这应该非常简单。

Model object 模型对象

class Race {

    def distance = "1/4 mile"
    def racer1
    def racer2
}

RaceController renders here RaceController在这里渲染

def doFullRace(Race race) {

            render (view: 'raceProgress', model: [race: race])
        }

and raceProgress.gsp should display it easily enough 并且raceProgress.gsp应该足够容易地显示它

    <html>
    <body>
        <div id="raceStart" align="center">
...
            <p>${race.racer1} is racing ${race.distance} against ${race.racer2}</p>
        </div>
    </body>
    </html>

but I instead I get this 但我反而得到了 找不到对象

Any ideas on what basic thing I missed? 关于我错过的基本知识有什么想法吗?

You have the following: 您具有以下内容:

def doFullRace(Race race) {
    render (view: 'raceProgress', model: [race: race])
}

One of the ways for race to be null there is if all of the following are true: 如果满足以下所有条件,则racenull一种方法是:

  • Race is a domain class Race是领域类
  • The request submitted to doFullRace includes a request parameter named id 提交给doFullRace的请求包括名为id的请求参数
  • There is no record in the database with an id that matches params.id 数据库中没有与id匹配params.id

From http://docs.grails.org/3.3.9/guide/theWebLayer.html#commandObjects ... http://docs.grails.org/3.3.9/guide/theWebLayer.html#commandObjects ...

If the command object's type is that of a domain class and there is an id request parameter then instead of invoking the domain class constructor to create a new instance a call will be made to the static get method on the domain class and the value of the id parameter will be passed as an argument. 如果命令对象的类型是域类的类型,并且有一个id请求参数,则将调用域类的静态get方法以及该域的值,而不是调用域类的构造函数来创建新实例。 id参数将作为参数传递。

And... 和...

If the command object's type is a domain class and there is no id request parameter or there is an id request parameter and its value is empty then null will be passed into the controller action unless the HTTP request method is "POST", in which case a new instance of the domain class will be created by invoking the domain class constructor. 如果命令对象的类型是域类,并且没有id请求参数,或者没有id请求参数,并且其值为空,那么除非HTTP请求方法为“ POST”,否则将将null传递给控制器​​操作。将通过调用域类构造函数来创建域类的新实例。 For all of the cases where the domain class instance is non-null, data binding is only performed if the HTTP request method is "POST", "PUT" or "PATCH". 对于域类实例为非空的所有情况,仅当HTTP请求方法为“ POST”,“ PUT”或“ PATCH”时才执行数据绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM