![](/img/trans.png)
[英]grails <g:link tag sometimes works and sometimes doesn't>
[英]Grails custom tag doesn't work with <g:link params>
我在GSP页面中有一个<g:link action="test" params='["present": "yes"]'
标记,当单击该标记时,它会将我发送到以/test?present=yes
结尾的URL。
如果我定义此自定义标签库:
class HelperTagLib {
static defaultEncodeAs = 'html'
static returnObjectForTags = ['passthrough']
def passthrough = { Map attrs, Object body ->
return attrs
}
}
并将其添加到<g:link action="test" params='${passthrough(["present": "yes"])}'
标记中,突然我的URL以/test
结尾,完全失去了参数。
为什么会发生这种情况,我该如何解决?
允许您的taglib为您呈现该链接。 在gsp和taglib中尝试</g:passthrough>
def passthrough = { attrs, body -> out << g.link(controller: 'foo', action: 'test', params: [present: 'yes']) }
我可以看到您在对taglib的调用中错过了g.taglibname ,它应该像这样
<g:link action="index" params="${g.doSomething(present:true)}">Ir</g:link>
我做到了我的自我和工作
但是,如果您要截取一些参数,然后在完成请求之前进行处理,也许更好的解决方案是使用beforeInpreceptor功能或某些过滤器。
有关拦截器的更多信息, 请参见http://www.grails.org/doc/2.3.x/ref/Controllers/beforeInterceptor.html
希望它可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.