Reputation: 113
I have command object like this:
@Validateable
class TaCustomerBoardActionCommand {
TaCustomerBoardAction action
static constraints = {
action casecade: true
}
}
and classes in command object below:
class TaCustomerBoardAction {
TaCustomerBoard taCustomerBoard
TaapAction taapAction
Date dateCreated // updated by grails
Date lastUpdated // updated by grails
User createdBy
OrgUnit orgUnit
Client client
static belongsTo = [Client]
static constraints = {
}
}
and
TaapAction {
int id
User createdUser
User responsibleUser
Brand brand
BusinessType businessType
Topic topic
Topic subTopic
String subject
String description
Date targetDate
int progress
String responsible
Client client
static belongsTo = [Client]
OrgUnit orgUnit
Date dateCreated // updated by grails
Date lastUpdated // updated by grails
TaapActionState taapActionState
static constraints = {
subject nullable: false, size: 1..64
description nullable: false, size: 1..4000
responsible nullable: false, size: 1..512
progress nullable: false
responsibleUser nullable:false
brand nullable:false
businessType nullable:false
topic nullable:false
subTopic nullable:false
targetDate nullable:false
}
TaCustomerBoard has similar constraints as above class. but it gives exception instead of error codes. Below is controller Post method:
def saveTaCustomerBoardAction(TaCustomerBoardActionCommand cmd){
if(cmd.validate()){
taActionPlanningService.saveAction(cmd.action.taapAction)
cmd.action.save(flush: true, failOnError: true)
}
[cmd:cmd]
}
Stack trace:
grails.validation.ValidationException: Validation Error(s) occurred during save(): - Field error in object 'de.idare.move.taap.TaapAction' on field 'progress': rejected value [null]; codes [de.idare.move.taap.TaapAction.progress.typeMismatch.error,de.idare.move.taap.TaapAction.progress.typeMismatch,taapAction.progress.typeMismatch.error,taapAction.progress.typeMismatch,typeMismatch.de.idare.move.taap.TaapAction.progress,typeMismatch.progress,typeMismatch.int,typeMismatch]; arguments [progress]; default message [Data Binding Failed] - Field error in object 'de.idare.move.taap.TaapAction' on field 'description': rejected value [null]; codes [de.idare.move.taap.TaapAction.description.nullable.error.de.idare.move.taap.TaapAction.description,de.idare.move.taap.TaapAction.description.nullable.error.description,de.idare.move.taap.TaapAction.description.nullable.error.java.lang.String,de.idare.move.taap.TaapAction.description.nullable.error,taapAction.description.nullable.error.de.idare.move.taap.TaapAction.description,taapAction.description.nullable.error.description,taapAction.description.nullable.error.java.lang.String,taapAction.description.nullable.error,de.idare.move.taap.TaapAction.description.nullable.de.idare.move.taap.TaapAction.description,de.idare.move.taap.TaapAction.description.nullable.description,de.idare.move.taap.TaapAction.description.nullable.java.lang.String,de.idare.move.taap.TaapAction.description.nullable,taapAction.description.nullable.de.idare.move.taap.TaapAction.description,taapAction.description.nullable.description,taapAction.description.nullable.java.lang.String,taapAction.description.nullable,nullable.de.idare.move.taap.TaapAction.description,nullable.description,nullable.java.lang.String,nullable]; arguments [description,class de.idare.move.taap.TaapAction]; default message [Property [{0}] of class [{1}] can not be null]
Kindly help me I am stuck with this problem.
Upvotes: 0
Views: 1047
Reputation: 1467
Just remove the failOnError: true
. You'll be able to process error objects instead of catching exception.
Upvotes: 0
Reputation: 8587
Your problem is rather straight forward. Well it would seem, you have provided how things work but not actually provided what is sent. My suggestion is to do a println params
in the controller action using validation method to see what it is sent / and validated.
You have declared progress as int
and not Integer
. This means it can't be nullable. Always use Boolean Integer or whatever the case maybe if something is meant to be nullable. Secondly you have also declared description and progress as nullable false meaning they have to be provided. The error message suggests command sent does not have a progress or description sent to it as part of the validation. This is something you need to investigate further by simple debugging such as println at your end to figure out why that is the case.
int progress
...
static constraints = {
progress nullable: false
description nullable: false, size: 1..4000
}
Upvotes: 0