在Grails中创建自定义标记库时出错

时间:2013-11-18 06:44:34

标签: grails gsp taglib

我正在尝试使用grails标签库。我创建了一个名为isowner

的简单标记库
class AuthTagLib {
static defaultEncodeAs = 'html'

def springSecurityService

def isOwner = { attrs, body ->
    def loggedInUser = springSecurityService.currentUser
    def owner = attrs?.owner

    if(loggedInUser?.id == owner?.id) {
        out << body()
    }
}}

然后尝试将其与gsp一起使用:

<g:isOwner owner="${leaveFormInstance.employee}">
                    <g:link class="edit" action="edit" resource="${leaveFormInstance}">
                        <g:message code="default.button.edit.label" default="Edit" />
                    </g:link>
</g:isOwner>

现在应该将用户对象作为输入并验证用户是否是帖子的所有者。

现在一切正常但在输出html中它将链接显示为文本。 enter image description here

我对这些东西不熟悉并且必须缺少一些基础知识可以帮助你。

1 个答案:

答案 0 :(得分:6)

删除

static defaultEncodeAs = 'html'

因为那是在逃避你的输出。