简体   繁体   中英

Grails optionValue displaying 'null' in g:select tag

I'm running into the issue that with my grails select tag. If the values in the optionValue field are null , it actually displays null . Is there a way to do some safe null checking and display a blank (or nothing at all) if the value is null? The select I have is

<g:select name="epoc" value="${travelInstance?.epoc?.id}" from="${user?.epocs}" optionKey="id" optionValue="${{it.firstName + ' ' + it.lastName}}" noSelection="${['null':' ']}" disabled="${disabled}"/>

If the firstName field is null it will display something like null Jones . Is there any way for it to display just Jones ?

您可以使用三元运算符轻松解决此问题,如下所示:

${{(it?.firstName ? it.firstName + ' ' : '') + it.lastName}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM