Grails groovy code mixed in the view
Hey. I need to do something like this:
<td><g:formatDate format="yyyy-MM-dd" date="${it.conference.s开发者_如何学PythontartDate}"/> (S) <u><g:formatDate format="yyyy-MM-dd" date="${it.conference.endDate}"/></u> (E)<br>
<%
def temp = new Date()
def temp2 = ${it.conference.startDate}
def temp3 = temp - temp2
out << temp3
%>
</td>
But for some reason, this isnt working, and i this the acess: ${it.conference.startDate}
inside groovy code isnt working. Any help would be apreciated.
Inline code in views is notorious for being a bad design choice. Generally speaking you'd be better off creating a custom taglib to display your date. A few immediate benefits from this:
- Debugability
- Testability
- Reuse
You ought to be able to pretty much drop your existing code into a custom taglib and invoke it without any significant changes.
精彩评论