Bind a string to a list in a command object

44 Views Asked by At

I have a web application writte in Grails 3.3.x. with GSP. Inside a GPS I have this select:

<g:select id="star" name="star"
          from="${[['name': '5 star', 'id': '5'], ['name': '4 stelle', 'id': '4'], ['name': '3 stelle', 'id': '3'], ['name': '2 stelle', 'id': '2'], ['name': '1 stelle', 'id': '1']]}"
          value="${currentStarValue}"
          optionKey="id" optionValue="name"
          multiple="multiple" class=" form-control select2" style="width: 100%;"/>

When I submit the form that include this select, I bind it with a simple obj command:

class SimpleCommand implements Validateable {

    String filter
    List lFilter = []
    List star
    long id
 }

If I choose from the select multiple values it works fine. My List star variable is correctly populated, but if I choose only one value it is empty. Reading from the params variable I see that if the values are multiple I got a string array, but if it is a single variable it's just a string that of course does not match a list.

0

There are 0 best solutions below