ValidateWholeObject bug?


I think I'm having an issue with ValidateWholeObject - either that or I'm not using it correctly. It seems to be returning true even when there are errors in other nested objects or wrapped enumerables. My expectation is that ValidateWholeObject will return false if any nested object is invalid. If you can provide an example showing ValidateWholeObject working correctly then maybe that will help me find any possible problem in my code.


frankabbruzzese wrote Apr 15, 2011 at 9:50 AM

ValidateWholeObject has the main purpose of making all errors appear on the screen, and then it should return false in case any nested wrapper detects an error. So if you dected an anomalou behavior, please give me more information

wrote Aug 3, 2011 at 11:57 AM

stirol29 wrote Aug 3, 2011 at 12:37 PM

I have the same bug with ValidateWholeObject - it is always true. I tried to check if my object is valid using Error property of BindWrapper class but it contains errors only from [Required] validation attributes(can be another bug?), so if my object has other attributes I can validate it only in view using Validation.Error event.

frankabbruzzese wrote Aug 3, 2011 at 1:54 PM

The ValidateWholeObject just check the object level validation errors, that is the errors that are defined with attributes that are put on the whole class, not on single properties that can be represented into a TextBox(WholeObject in the name stands just for this). It needs to be called JUST AFTER all of the simple errors have been cleared by the user. The correct way to operate is the one shown in the wpf example that comes with the binaries.
1) One first check that there are no simple errors, by using the error event.
2) When all simple property have been cleared (validationErrorNumbers == 0 in the example) we are sure that all single properties have a meaningful value and we can call ValidateWholeObject to verify that the whole tree of object is in a coherent state, that is to apply overall business validation rules. This cannot be done before, when for instance, the value of a numeric textbox is a string that cannot be converted into a numeric value. Thus the error correction process needs to happens into two stages:
Simple property errors are shown to the user as soon it insert a value for the property. Overall coherence errors are checked after all single properties have been provided correctly when the user has finished input and submit it to the system. This rules check the overall coherence of the input.
An example of object level property is the one defined by the IntervalValidator class and applyed at the root of each interval this way: [CustomValidation(typeof(IntervalValidator), "Validate")]. This rule check that Low<High. To convince yourself that this works violate this rule in the inner interval (the one contained in the main interval as a property value) while keeping everyting else ok. This means clearing all simmple property attributes on the screen, and choosing Low<High in the main interval.
If you put a breakpoint in the event handler of the send button you will see that ValidateWholeObject returns false.

wrote Feb 14, 2013 at 1:57 AM