Skip to main content

Posts

Showing posts with the label grails cross-field validation using controllers

Grails - cross-field Date validation - Method using controllers

In continuation of my earlier post on the cross-field date validation , I'm going to discuss another method using grails controller. The following code in "save" and "update" method of the controller validates the date fileds used in the student domain object that is discussed in the previous post def save = { def studentInstance = new Student (params) if (studentInstance.endDate.before(studentInstance.startDate)) { studentInstance.errors.rejectValue('endDate', 'student.endDate.shouldbegreater') } ... .. } Note that the code highlighted as bold is the addition to the boiler-plate code generated by using the grails command "grails generate-all" on the domain class "Student" Following message is to be added to the "messages.properties" file