Grails - date binding in the controller

I am trying to bind date parameters in my controller. I read somewhere that this should be enough if I have a date in format yyyy-MM-dd HH:mm:ss.S. But that does not work. Another option, which I read was to add tags _day, _month, _yearetc. To the attributes I want to parse, but this method also doesn't work.

So, this is basically a one-to-many relationship when there is a date on many sides (the action has a VisitList<Visit>date of visit).

// domain classes
class Action {
   List<Visit> visitList
   static hasMany = [visitList: Visit]
}

class Visit {
   Action action 
   static belongsTo = [action: Action]

   Date date
   String description
}

I analyze all the parameters for the action instance as follows:

// in controller
def save(){
   Action actionInstance = new Action()
   action.properties = params
   action.save()
}

The date is sent from the view and has this format:

visitList[0].date=2012-05-15 00:00:00.0000

But the date is still zero. A visit also has a description attribute, and it works well. Parameter for this attribute:

visitList[0].description=description

.

+3
2

, ? , , , Date, Date.parse() grails 2.0, :

Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(dateString)
def action = new Action()
def visit = new Visit(date: date, description: description?:"", action: action)
visit.save()
action.visitList.add(visit)
action.save()

-HTH

+1

, . Command Object. ? ? , . , , DateFormat {, parse()}.

0

All Articles