List of fields in error of a domain instance

29 / Apr / 2010 by Bhagwat Kumar 0 comments

I have been working with domain and command object validation. I needed to get all the fields in error as a list so that I can display a single line error message like : please enter valid values in the following fields- filed1, field2. Another use case was to check the list of fields for error. Here is the code to get list of errorneous fields:

List fieldsInError = domainInstance.errors.allErrors.collect {['field']}

// Generate error message

String errorMessage= "Enter valid values in fields - ${fieldsInError.join(', ')}"

// check if both field1 and field2 are in error

if(fieldsInError.containsAll(['field1', 'field2']){
	// Both the fields are in error irrespective of other fields

Hope it helps you guys too.

~~~~Bhagwat Kumar~~~~
IntelliGrape Software


Leave a Reply

Your email address will not be published. Required fields are marked *