Grails - Set "disabled" attribute name and value in GSP

David Morabito picture David Morabito · May 19, 2011 · Viewed 10.2k times · Source

I´m trying to do this without success:

<g:textField title="${title}" ${disabled} />

I want to apply a disabled attribute, ONLY if the ${disabled} variable is TRUE. I don't want to use conditionals, because in other views I got a lot of code and using IF statements, will be a chaos.

The other thing is applying the attribute like this:

<g:textField title="${title}" disabled="${disabled}" />

But when I put the disabled attribute, no mather the content of the variable, It just always disables the field.

Answer

Grooveek picture Grooveek · May 19, 2011

if you don't like gotomanners' solution (which seems perfectly valid to me)

<g:textField title="${title}" ${(disabled)?"disabled":""} />