Grails

Make Command Object error decoration to be more like Domains

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major 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

Activity

Hide
Ross Niemi added a comment -

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
}
Show
Ross Niemi added a comment - 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
}
Hide
Jeff Brown added a comment -

I think that this issue was resolved with GRAILS-5764

Show
Jeff Brown added a comment - I think that this issue was resolved with GRAILS-5764

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: