开发者

Grails GSP render problem

I've got a domain class which I want to, at run time, do a database call to populate a list of objects as a property. I have a tree with a 'headMember' property and that property is an object which has the following function:

def marriages = {
    def marriages = Marriage.findAll("from Marriage as m where m.mainMember.name=:name", [name:name])
    return [marriages:marriages]
}

in my GSP, I use ${tree?.headMember?.marriages} to access the 'headMember' property of the model which is passed to the view 'tree' from the following function in the relevant controller:

def show = {
        def tree = Tree.get(params.id)
        render(view:'show', model:[tree:tree])
    }

when I view this in my browser, i get:

Member$_closure1@3708ab98

w开发者_开发技巧here I'd expect a list.

Any ideas what I'm doing wrong?

Cheers.


When you call marriages, you are calling a closure and this closure is returned. I think that you should rework it to be a method, something like that:

static transients = ['marriages'] // tell hibernate that marriages is not a persistent property

List<Marriages> getMarriages(){
    return Marriage.findAll("from Marriage as m where m.mainMember.name=:name", [name:name])    
}

This way, when you call ${tree?.headMember?.marriages} in your GSP, the getMarriages() method is called and list of marriages should be returned.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜