开发者

Grails: How to edit GSP (views/show) to show desired info

开发者 https://www.devze.com 2023-01-07 05:20 出处:网络
I have two Domain classes (Drives & Computer) class Computer { static hasMany = [drives:Drive] String computerName

I have two Domain classes (Drives & Computer)

class Computer {

    static hasMany = [drives:Drive]
    String computerName

    static constraints = {
    computerName(nullable:false)
    }
}


class Drive {

    static belongsTo = Computer
    Computer computerName

    static constraints = {
    computerName(nullable:false)
    }
}

Wh开发者_高级运维en the application is run and the DriveController is clicked, the drop menu for Computer Name shows something like: computer: 1

My desired output is what I actually have entered for the computer: 1 which in my instance was Owner987

I have generated my views and believe I need to edit a g.link, perhaps in show.gsp of Drive.

All help is appreciated.


By default it will show the toString() output, so override that to show what you want:

class Computer {

    static hasMany = [drives:Drive]
    String computerName

    String toString() { computerName }
}

Also note that properties are not-null by default so you can omit the nullable:false constraints in both classes.

0

精彩评论

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