Grails GSP null security check problem
I am trying to populate a textbox in my GSP as such:
<label>Phone(aaa-bbb-cccc):</label> <g:textField name="phone" style ="border-radius: 5px"
value="${recordToEdit.telephones = [] ? null : recordToEdit.telephones.first()}"></g:textField><br>
but it still tells me that I cannot access first () on an empty list. phones is a list of strings, each of which is a phone number.
+3
source to share
3 answers
as @ gross-jonas pointed out is recordToEdit.telephones = [] ? .. : ..
already terribly wrong unless it's a typo
the check you are trying to do should look like this:
value="${recordToEdit.telephones ? recordToEdit.telephones.first() : ''}"
or
value="${recordToEdit.telephones?.getAt( 0 ) ?: ''}"
+5
source to share