Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Duplicate
-
Affects Version/s: 1.2 final
-
Fix Version/s: None
-
Component/s: Controllers
-
Labels:None
Description
The error decoration-methods for both Command Objects and Domain Classes can be found in the following files respectively:
- ./grails/src/java/org/codehaus/groovy/grails/plugins/web/ControllersGrailsPlugin.groovy
- ./grails/src/java/org/codehaus/groovy/grails/plugins/DomainClassGrailsPlugin.groovy
Errors for both Command Object and Domain Class are indexed as follows:
- Command Object - class name
- Domain Class - class name + hashCode
This means that if there are multiple command instances of the same type, the errors will be shared between all those instances (i.e. since they use the same "class name" key).
If the Command Object error methods (i.e. getErrors, setErrors) had the same implementation as a Domain class then it would/should be possible to use multiple commands of the same type via action-injection or manually via bindData.
Issue Links
| This issue duplicates: | ||||
| GRAILS-5764 | Unexpected command object errors rendered |
|
|
|
Command Object Error methods:
commandObjectMetaClass.setErrors = {Errors errors -> RCH.currentRequestAttributes().setAttribute("${commandObjectClass.name}_errors", errors, 0) } commandObjectMetaClass.getErrors = {-> RCH.currentRequestAttributes().getAttribute("${commandObjectClass.name}_errors", 0) }Domain Class Error methods:
metaClass.getErrors = {-> def errors def key = "org.codehaus.groovy.grails.ERRORS_${delegate.class.name}_${System.identityHashCode(delegate)}" errors = get(key) if(!errors) { errors = new BeanPropertyBindingResult( delegate, delegate.getClass().getName()) put key, errors } errors } metaClass.setErrors = { Errors errors -> def key = "org.codehaus.groovy.grails.ERRORS_${delegate.class.name}_${System.identityHashCode(delegate)}" put key, errors }commandObjectMetaClass.setErrors = {Errors errors -> RCH.currentRequestAttributes().setAttribute("${commandObjectClass.name}_errors", errors, 0) } commandObjectMetaClass.getErrors = {-> RCH.currentRequestAttributes().getAttribute("${commandObjectClass.name}_errors", 0) }metaClass.getErrors = {-> def errors def key = "org.codehaus.groovy.grails.ERRORS_${delegate.class.name}_${System.identityHashCode(delegate)}" errors = get(key) if(!errors) { errors = new BeanPropertyBindingResult( delegate, delegate.getClass().getName()) put key, errors } errors } metaClass.setErrors = { Errors errors -> def key = "org.codehaus.groovy.grails.ERRORS_${delegate.class.name}_${System.identityHashCode(delegate)}" put key, errors }