我在.gsp文件中有这个<g:select> 。 但是,与任何普通的<g:select>不同,如果满足某个条件,则该属性将具有disabled="" 。
遵循以下代码:
<g:select name="test" from="${["foo1","foo2"]}" <g:if test="${true}">disabled=""</g:if> />它返回了一个错误: Grails tag [g:select] was not closed
但是当我把它改成这个时:
<g:select name="test" from="${["mu1","mu2","mu3"]}" ${ if(true) { println "disabled=\"\"" } }/>它返回了此错误: Attribute value must be quoted.
这两个错误消息都在异常下, org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
问题是我们如何才能使这项工作成功? 没有使用自定义TagLib,是否有可能的答案?
I have this <g:select> in a .gsp file. But unlike any ordinary <g:select>'s this one would have the attribute disabled="" if a certain condition is met.
Following the code:
<g:select name="test" from="${["foo1","foo2"]}" <g:if test="${true}">disabled=""</g:if> />It returned an error: Grails tag [g:select] was not closed
But when I change it into this:
<g:select name="test" from="${["mu1","mu2","mu3"]}" ${ if(true) { println "disabled=\"\"" } }/>It returned this error: Attribute value must be quoted.
Both of the error message are under the exception, org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
The question is how could we make this work? Is there a possible answer without using a custom TagLib?
最满意答案
GSP表单字段标记将disabled视为布尔属性,因此您可以这么说
<g:select .... disabled="${true}" />通常你应该能够在通常的Groovy-truth规则下使用任何表达式,但我相信它为字符串“true”和“false”提供了一个特例(后者在Groovy-truth规则下通常被认为是非-empty string)。 如果有疑问你可以随时说
disabled="${(someExpression) as boolean}"The GSP form field tags treat disabled as a boolean property, so you can say
<g:select .... disabled="${true}" />Generally you should be able to use any expression under the usual Groovy-truth rules but I believe it makes a special case for the strings "true" and "false" (the latter would normally be considered true under Groovy-truth rules as a non-empty string). If in doubt you can always say
disabled="${(someExpression) as boolean}"更多推荐
<g,disabled,select,电脑培训,计算机培训,IT培训"/> <meta name="descrip
发布评论