I’m just starting out with Grails, transitioning from Javascript
In a controller, I’m trying to do this below, but I get an error
def list = {
def projects = Project.list()
projects.each {
it.dateCreated = it.dateCreated.format('mm/dd')
println it.dateCreated
}
return [projectInstanceList: projects,
projectInstanceTotal: projects.size()]
}
In my view I then display the dateCreated for a project, I just want to format the date so it’s cleaner/more concise.
This is my error:
'java.lang.String' to class 'java.util.Date'
I also tried assigning this to it.dateCreated
new Date(2011, 09, 31, 10, 57, 00)
But that gave a similar error also.
First, you should never change a domain instance property like that just for “display” purposes. The reason for that is the domain instance is actually going to be persisted with your changes when the hibernate session flushes.
Second, let the view display the property in the correct format. That’s the responsibility of the view, not the domain instance, or the controller.