Alberto Vilches
2014-05-22 07:16:38 UTC
Hi. I'm not sure if this is a bug or it's a feature I'm using wrong. I'm
trying to do some extra bindings in a controller command using
the DataBindingListener. I've extended DataBindingListenerAdapter and I've
implemented the void afterBinding(Object t, Object errors) method. In this
method, I got the errors object as a parameter, so after bind some
attributes, I validate them and I reject them if they have errors. I kind
of:
void afterBinding(Object t, Object errors) {
t.foo = Bar.findByBlaBla(...)
if (t.foo.wrong) errors.rejectValue("foo", "wrong")
}
Everything is ok, but when I get the command in my action, my errors are
not there. I debug it and I that's because the controller calls to the
validate() method in my command, so all my errors from the afterBinding
method are cleared and the command is validated only against his
constraints.
So, what's the point to send the errors object to the afterBinding method,
if new errors are cleared when the action calls to the validate method()? I
guess the same for the other methods. If it's a bad practice doing extra
validation with errors manipulation in the binding method, when should I do
that?
PS: I fixed that extending my command with another class, overriding the
validate() method and doing in this method a super.validate() then my extra
validations. Not sure if this is a good place to do that.
trying to do some extra bindings in a controller command using
the DataBindingListener. I've extended DataBindingListenerAdapter and I've
implemented the void afterBinding(Object t, Object errors) method. In this
method, I got the errors object as a parameter, so after bind some
attributes, I validate them and I reject them if they have errors. I kind
of:
void afterBinding(Object t, Object errors) {
t.foo = Bar.findByBlaBla(...)
if (t.foo.wrong) errors.rejectValue("foo", "wrong")
}
Everything is ok, but when I get the command in my action, my errors are
not there. I debug it and I that's because the controller calls to the
validate() method in my command, so all my errors from the afterBinding
method are cleared and the command is validated only against his
constraints.
So, what's the point to send the errors object to the afterBinding method,
if new errors are cleared when the action calls to the validate method()? I
guess the same for the other methods. If it's a bad practice doing extra
validation with errors manipulation in the binding method, when should I do
that?
PS: I fixed that extending my command with another class, overriding the
validate() method and doing in this method a super.validate() then my extra
validations. Not sure if this is a good place to do that.
--
Un saludo.
Alberto Vilches
http://albertovilches.com
Twitter: @albertovilches
Un saludo.
Alberto Vilches
http://albertovilches.com
Twitter: @albertovilches