Search code examples
grailsgsp

Tag "Select" in gsp


How to correctly use tag select in gsp while passing to it ArrayList<String> ? I know how to use it this my own composed objects, for example:

<g:select name="tablePlacesAvailable" from="${tableInfo}" optionValue="${{it.placesInTableAmount}}" optionKey="placesInTableAmount" value=""/>

But how to use it with built in objects, like String?


Solution

  • If you want to use a g:select with a list of String

    <g:select name="selection" from="${values}" />
    

    Where values is a collection of Strings. My controller code is

    class DemoController {
        def index() { 
            [values: ["This", "is", "a", "test"]]
        }
    }