我有以下组合框:
<g:select name="ticketType" from="${app.domain.enums.TicketType?.values()}"
keys="${app.domain.enums.TicketType.values() }"
value="${ticketInstance?.ticketType}"
noSelection="${['null': 'Select One...']}"
/>
Run Code Online (Sandbox Code Playgroud)
我在命令对象中为ticketType设置了以下约束
ticketType nullable: true, blank:true
Run Code Online (Sandbox Code Playgroud)
TicketType是一个非常简单的枚举:
public enum TicketType {
QUESTION, SUPPORT, MAINTENANCE, NEW_FUNCTIONALITY, MALFUNCTION
}
Run Code Online (Sandbox Code Playgroud)
每次我没有在我的GSP中为ticketType设置一些值时,我收到以下错误:
Failed to convert property value of type 'java.lang.String' to required type 'com.coming.enums.TicketPriority'
Run Code Online (Sandbox Code Playgroud)
这就像没有选择g:select设置"null"(字符串)的值.
我错过了什么?
小智 15
您是否尝试使用空字符串作为noSelection属性,而不是使用'null'文字?例如noSelection="${['':'Select One...']}"?这可以在数据绑定期间正确转换为真正的空值.