GSP g: default option selection

Is it possible to select the default parameter field in the tag g:select?

I only saw the noSelection parameter in the documentation.

<g:select name="user.age" from="${18..65}" value="${age}"
      noSelection="['':'-Choose your age-']"/>

But I need a default choice from the data I received.

For example, 18..65 is my range, and I want to choose 20 by default.

Is this possible or do I need to do this using javascript?

thanks

+5
source share
1 answer

The attribute valuedoes just that. From the Grails documentation:

value (optional) - the current selected value, which evaluates equals () as true for one of the items in the list.

, "20", age null,

<g:select name="user.age" from="${18..65}" value="${age ?: 20}"
      noSelection="['':'-Choose your age-']"/>
+13

All Articles