Grails g:select no selection

Viewed 9034

I have the following combobox:

<g:select name="ticketType" from="${app.domain.enums.TicketType?.values()}"
                              keys="${app.domain.enums.TicketType.values() }"
                              value="${ticketInstance?.ticketType}"
                              noSelection="${['null': 'Select One...']}"
                    />

I've setup the following constraint for ticketType in command object

ticketType nullable: true, blank:true

TicketType is a very simple enum:

    public enum TicketType {
        QUESTION, SUPPORT, MAINTENANCE, NEW_FUNCTIONALITY, MALFUNCTION
}

And every time I don't setup some value for ticketType in my GSP I get the following error:

Failed to convert property value of type 'java.lang.String' to required type 'com.coming.enums.TicketPriority'

It's like in case of no selection g:select sets the value for "null" (string).

What am I missing?

3 Answers

Under Rails 3.3.x, no variation of providing the "null" value worked. In the end, I resolved it by adding this line in to the controller+action before doing any use of the params:

// convert "null" strings to REAL nulls
params.account.each { it.value = (it.value == 'null' ? null : it.value) }

After that, the following worked fine:

account.properties = params.account
Related