|
From: Rob R. <rob...@ur...> - 2004-04-22 12:52:01
|
Got a question about FieldError and validation. I know it's created by DataBinder, and the ctor for FieldError creates three codes for message lookup, which is nice. However, we'd like for additional codes to be generated in the case of nested properties. Our problem is that we have several different UI's where coordinate information is entered, but the coordinate properties are at different nested paths, so we can't have something like "typeMismatch.latitude.degrees". Instead, we'd need to do "typeMismatch.someObject.someProperty.latitude.degrees" and so on for all of the different objects that have coordinate properties. We're going to write a NestedFieldError class that looks for nested properties in the "field" value when a FieldError is constructed. This will allow us to have a generic "typeMismatch.latitude.degrees", or even a "typeMismatch.degrees" error message, which will be very nice. Unfortunately, this will involve extending DataBinder as well so that it uses our NestedFieldError class. We'll have to override the bind method. I'm wondering - has anyone else needed this functionality? Would it be too special-case to add it to the Spring validation package? What could at least be done is to factor out how DataBinder creates instances of FieldError - maybe toss it into a protected method so that a subclass could easily override it, or just refactor it into something pluggable and use the current approach as the default. Rob |