Grails: Call taglib from g:if tag

被刻印的时光 ゝ 提交于 2019-11-28 05:05:10

问题


I have a custom tag lib that returns a Boolean object so that my GSP can decide whether to display a piece of html or not. I would like to use the g:if tag to check this Boolean's value since I also need to check a few other values (that aren't accesible in the taglib). However, I don't know how to actually call the taglib from the tag?

I've tried:

<g:if test="${<custom:tag/> && other.boolean}">

but that throws errors.

I also tried:

<g:if test="<custom:tag/> && ${other.boolean}">

but that throws errors too.


回答1:


How does the taglib look like? Looking at the usage it should be as below:

class SomeTagLib {
    static namespace = "custom"
    static returnObjectForTags = ['tag']

    def tag = { attrs, body ->
        //returns an object (can be boolean)
    }
}

By default, taglibs would return StreamCharBuffer. If you need an object to be returned, (as in your case to be used as part of conditional statement), I guess you would need returnObjectFromTags as shown above. It specifies which tag deviates from default behavior and returns an object instead.

Also, you should be using the taglib as mentioned by Tim:

<g:if test="${custom.tag() && other.boolean}"> //should be the appropriate way


来源:https://stackoverflow.com/questions/21991970/grails-call-taglib-from-gif-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!