简体   繁体   中英

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.startDate}"/> (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.

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