我在<g:select>
文件中有这个.gsp
。但是,与任何普通的<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
异常(exception)下问题是我们如何使这项工作可行?如果不使用自定义TagLib,是否有可能的答案?
最佳答案
GSP表单字段标签将disabled
视为 bool(boolean) 属性,因此您可以说
<g:select .... disabled="${true}" />
通常,您应该能够在常规的Groovy-truth规则下使用任何表达式,但我认为它对字符串“true”和“false”具有特殊情况(在Groovy-truth规则下,后者通常被视为
true
,因为-空字符串)。如有疑问,您可以随时说disabled="${(someExpression) as boolean}"
关于grails - <g:select>中的Grails <g:if>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12507918/