开发者

grails databinding get id from select

hey. i have something like this:

class Car{
String name

}

class Volante{
String name
Car car
}

And my gsp file:

<g:form controller="volante" action="save">
<label>Car</label>
<g:select name="car.id" from="${cm.Car.list()}" optionKey="id" value="${car?.id}"  /><br><br><br>

<label>name
</label>
<input type="text" name="name" value="${volante?.name开发者_开发知识库}" />
</g:form>

def save = {
        def volante= new Volante()



        volante.car = params.car.id ################

        volante.name = params.name



          if (!volante.save(failOnError: true)) {
        render (view: "/participatedAdd", model : [volante: volante])
        return
    }

        render(view: "/participated")

    }

I have problems where i have the ###########. How can do this like that=? I dont know how to get the car id to link to the volante.car. Any help would be apreciated.

PS. i dont use def volante= new Volante(params) because my view is more complex than this. And do i have to use in the values from the view "className.attribute" ?? Because im binding multiple domain classes.?


def car = Car.get(params.car.id)
volante.car = car

Have you tried something like this ?


You might try:

volante.car = Car.get(params['car.id'])

But you could also just use Grails' data binding to bind the specific property:

def volante = new Volante()
volante.properties['car'] = params

Since the parameter name is car.id, Grails will recognize that you're mapping the association by id and bind it for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜