Last updated by
4 years ago
Page: button, Version:0
import org.springframework.beans.SimpleTypeConverterimport org.springframework.web.servlet.support.RequestContextUtils as RCU
import org.codehaus.groovy.grails.commons.DomainClassArtefactHandlerclass SelectTagLib { static namespace = 'select'
def out // to facilitate testing /
Please choose' first item is supplied, write it out
out << '<option value="' << (noSelectionKey == null ? "" : noSelectionKey) << '"'
if (noSelectionKey.equals(value)) {
out << ' selected="selected" '
}
out << '>' << noSelectionValue.encodeAsHTML() << '</option>'
} private String optionValueToString(def el, def optionValue) {
if (optionValue instanceof Closure) {
return optionValue(el).toString().encodeAsHTML()
} eloptionValue (+).toString().encodeAsHTML()
}}
- A helper tag for creating HTML selects
- Examples:
- <g:select name="user.age" from="${18..65}" value="${age}" />
- <g:select name="user.company.id" from="${Company.list()}" value="${user?.company.id}" optionKey="id" />
- Dump out attributes in HTML compliant fashion