У меня есть две командные объекты, один из них содержал список другихПривязать список объектов к команде Grails?
@grails.validation.Validateable
class SongCommand {
String title
List<CoupletCommand> coupletCommandList = [].withLazyDefault {new CoupletCommand()}
Boolean isChorusRepeat
static constraints = {
title blank: false, size: 1..129
coupletCommandList validator: { couplets, obj ->
def isValid = true
couplets.each {
isValid = isValid && it.validate()
}
return isValid
}
}
}
class CoupletCommand {
Integer coupletPosition
String coupletText
Boolean isChorus
static constraints = {
coupletText blank: false, size:20..700
isChorus nullable: true
}
}
От переднего конца к контроллеру я передал что-то вроде этого
[coupletText:2342342352342, coupletPosition:1, isChorus:false]
[coupletText:frfsdfsdf, coupletPosition:2, isChorus:true]
......
[coupletText:sd9f9s9df9, coupletPosition:n, isChorus:false]
при попытке сохранить список куплеты на контроллере
def saveCouplets() {
def songCommand = new SongCommand()
// bad, but not necessary now
def count = session['songId'] as Integer
def bindingMap
for (int i = 1; i <= count; i++) {
bindingMap = [coupletText: params['coupletText-' + i],
coupletPosition: params['coupletPosition-' + i],
isChorus: (params['isChorus-' + i]) ? params['isChorus-' + i] : false]
songCommand.coupletCommandList.add(bindingMap)
}
//Validate it
//if valid
if (songCommand.validate()) {
coupletService.addCouplets(bindingMap, params)
} else {
render model: [command: songCommand]
}
//else render view show model [command: command]
}
Получать сообщение об ошибке
groovy.lang.MissingMethodException Сообщение Нет подписи метода: java.util.LinkedHashMap.validate() применим для типов аргументов:() values: [] Возможные решения: wait(), values (), values ())