grailsgrails-3.3

Dropdown list in Grails 3


I'm developing an application using Grails 3.3.10, I'm trying to make a dropdown list but I'm getting it empty I'm putting the values in application.yml file, below is my code.

application.yml:

profile:
   accType: ['supplier', 'buyer', 'both']

Domain:

class Profile {
String accType
static constraints = {
accType(nullable: true, InList: Holders.config.getProperty('profile.accType'))
  }

} 

_form.gsp

<g:select required="" style="width:auto;" class="form-control input" name="accType" from="${Profile.constrainedProperties.accType.inList}" value="${profileInstance?.accType}" valueMessagePrefix="profile.accType"/>

Solution

  • You have this:

    static constraints = {
        accType(nullable: true, InList: Holders.config.getProperty('profile.accType'))
    }
    

    You probably want this:

    static constraints = {
        accType(nullable: true, inList: Holders.config.getProperty('profile.accType', List))
    }
    

    Note that InList should be inList with a lower case "i" at the beginning and you want to pass 2 arguments to the getProperty, the second argument being the List class literal.