开发者

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:

  1. Debugability
  2. Testability
  3. Reuse

You ought to be able to pretty much drop your existing code into a custom taglib and invoke it without any significant changes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜