我正在尝试简单使用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中,它将链接显示为文本。
我对这些东西不熟悉,必须缺少一些基础知识,您可以帮忙。
去掉
static defaultEncodeAs = 'html'
因为那逃避了您的输出。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句