Grails g: choose a choice

I have the following combo box:

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

I set the following restriction for the type ticketType in the command object

 ticketType nullable: true, blank:true 

TicketType is a very simple enumeration:

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

And every time I do not set any 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' 

As with g: select, sets the value to "null" (string).

What am I missing?

+6
source share
2 answers

Instead of using the literal 'null', have you tried using an empty string as the noSelection attribute? for example noSelection="${['':'Select One...']}" ? This can lead to the correct conversion to true null during data binding.

+14
source

As your error says - you have a line in noSelection . This cannot be converted to any of your enum values.

Remove the quotes from your null and it should work (it works for me with grails 2.0):

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

Source: https://habr.com/ru/post/921402/


All Articles