Я пытаюсь отобразить представление, которое отлично работает, но, похоже, оно не получает объект модели, который я ему передаю. Я не могу понять причину, так как это должно быть очень просто согласно всем руководствам и примерам.
Объект модели
class Race {
def distance = "1/4 mile"
def racer1
def racer2
}
RaceController рендеры здесь
def doFullRace(Race race) {
render (view: 'raceProgress', model: [race: race])
}
и raceProgress.gsp должен отображать его достаточно легко
<html>
<body>
<div id = "raceStart" align = "center">
...
<p>${race.racer1} is racing ${race.distance} against ${race.racer2}</p>
</div>
</body>
</html>
Любые идеи о том, какую основную вещь я пропустил?





У вас есть следующее:
def doFullRace(Race race) {
render (view: 'raceProgress', model: [race: race])
}
Один из способов race быть null есть, если верно все следующее:
Race — это доменный классdoFullRace, включает параметр запроса с именем idid, совпадающей с params.idИз 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.
И...
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. 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".
Это отличный ответ! Однако, как оказалось, это было не так уж и сложно. Я дважды визуализировал один и тот же вид, один раз без объекта модели.
racer1 является нулевым объектом, не знаю, почему ваши классы определили объекты как def - если вы добавите
<p>${race?.racer1} is racing ${race?.distance} against ${race?.racer2}</p>исключение нулевой точки исчезнет, но у вас все равно не будет данных