Hi guys,
Something I just noticed today...I haven't been watching the mailing
list closely, so pardon me if it's already been discussed at length.
I have a view with this code snippet. It's basically grabbing the
username from the user session and passing it to a domain object:
<g:if test="${prediction.canBeEditedBy(loggedInUserInfo(field:'username'))}">
<g:link action="edit" id="${
prediction.id}">${
prediction.name}</g:link>
</g:if>
with the implementation of the method looking like this:
def canBeEditedBy(username) {
if (!isPastDeadline() && (createdBy.username == username)) {
return true
}
false
}
When I upgraded to 1.2M4, this code broke. Here's some println's that show why:
println "username is [${username}]" -- dan
println "isPastDeadline is ${isPastDeadline()}" -- false
println "createdBy.username is [${createdBy.username}]" -- dan
...ok, looks good....
println "== is ${createdBy.username == username}" -- false ...huh????
println "createdBy.username class is ${createdBy.username.class}" --
java.lang.String
println "username class is ${username.class}" --
org.codehaus.groovy.grails.web.util.StreamCharBuffer
...ohhhh...that's why! It used to be String
This change happened as part of the 1.2M3 release, with the passive
view performance refactoring. I solved this problem by doing a
.toString() on the username before the comparison check. Something to
be aware of...
p.s. Improvement ideas are welcome!
Regards,
Dan