中的Grails (Grails in )

编程入门 行业动态 更新时间:2024-10-13 22:21:30
中的Grails (Grails in )

我在.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

本文发布于:2023-07-18 04:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154825.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Grails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!