validation of complex objects

Topics: Questions
Oct 23, 2012 at 2:35 AM

I am having issues with the InfoBarMessageControl when a complex VM is contained in the DataWindow.

Consider the following (simplified) example.

Model Classes:

  • DiaryEntry
    • contains info for a single entry in a work diary
      • client, date, timein, timeout,...
    • contains businessrules & field validation code
  • DiarySection
    • contains 1 or more DiaryEntries (for a specified date/time period)

ModelView Classes

  • DiaryEntryViewModel
    • contains single Model: DiaryEntry
  • DiarySectionViewModel
    • contains single Model: DiarySection

View classes

  • DiaryEntryView
    • contains controls for viewing / editing DiaryEntry
  • DiaryEntryWindow
    • contains a DiaryEntryView
  • DiarySectionWidow
    • contains a list control (eg listview, datgrid) (of DiaryEntry objects)
    • contains a DiaryEntryView
      • binds to the 'selected' item in the list control

Observed behaviour

  • DiaryEntryWindow behaves 'perfectly'
    • validation errors correctly shown by the InfoBarControl (when they exist)
    • This indicates that the DiaryEntry model is exhibiting correct behaviour
  • DiarySectionWindow
    • always display validation errors, irrespective of the state of any of the contained DiaryEntry objects.
      • it appears that the InfoBarControl is bound to the DiaryEntryModelView created by the DiaryEventView when the Window is first loaded. This VM is created before the DiarySection is properly populated, using the default constructor. Consequently it fails many validation tests.

It seems (to me) fairly obvious that the issue is how the DiarySectionViewModel is handling the validation, but I don't now ow to fix it.

 

Any suggestions / examples would be very welcome.

 

 

 

 

Oct 23, 2012 at 3:54 AM

Hi, just tried something else:

I replaced the DiaryEventView with a DiaryEventCtrl (ie non Catel user control) in the DiarySectionWindow.

Now the DiarySectionWindow behaviour is:

  • No validation errors displayed when first show the window.
    • most likely because the user control is working directly with the selected DiaryEntry
  • Validation errors correctly displayed (in the InfoBarControl) when I edit the selected DiaryEvent object to deliberatley create a validation issue.
  • Validation errors are not cleared when the selected object is edited to remove validation errors.

Also, the DiarySectionViewModel does not report any errors (via the IDataErrorInfo interface) in unit tests.

                var obj = new DiarySectionMgrViewModel();
                Console.WriteLine("\ntest of {0}\n==========", obj.GetType().Name);
                Console.WriteLine("object contains {0} work items", obj.WorkMgr.List.Count);

                var dei = obj as System.ComponentModel.IDataErrorInfo;
                Assert.AreNotEqual(null, dei, "object is a IDataErrorInfo");
                {
                    var error = dei.Error;
                    Console.WriteLine("dei.Error:\n{0}\n-----", error);

                    var field = "TimeOut";
                    var x1 = dei[field];
                    Console.WriteLine("dei[{0}]: {1}", field, x1);
                }

So, it appears to be a data binding notification issue with the DiarySectionViewModel. However I don't know how the InfoBarControl is doing its binding

Coordinator
Oct 24, 2012 at 3:59 PM

Please provide a zip file with the example files you got, then we will fix it.

Oct 24, 2012 at 7:02 PM

Ok, I will put together a small sample which demonstrates the issue.

Not sure how to upload it to you...

Coordinator
Oct 24, 2012 at 7:20 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Oct 24, 2012 at 7:21 PM

You can upload it to the workitem I just created.