Validation on children controls

Validation on children controls

Old forum URL: forums.lhotka.net/forums/t/3307.aspx


justinPlaianul posted on Wednesday, August 01, 2007

Hi,

 

I have the following scenario:

 

 

There are two WPF user controls named, for example, PersonalInformationUserControl and AddressDetailsUserControl. The first one contains the second.

In the business layer there are 2 classes, PersonalInformation and AddressDetails. Both of them derive from BusinessBase. PersonalInformation class has an AddressDetails member type.

PersonalInformationUserControl has a CslaDataProvider that points to a PersonalInformation object. AddressDetailsUserControl uses the same CslaDataProvider as PersonalInformationUserControls but its fields are bound to the AddressDetails member of PersonalInformation object.

Furthermore, PersonalInformationUserControl has a Save button that is declared like this:

<Button x:Name="btnSave" Content="Save" Grid.Row="5" IsDefault="True"

      Command="ApplicationCommands.Save"

      CommandTarget="{Binding Source={StaticResource MyPerson}, Path=CommandManager, BindsDirectlyToSource=True}"/>               

                               

In the same time, the two user controls derive from EditForm class.

The two business classes have some business rules. For example, PersonalInformation applies Csla.Validation.CommonRules.StringRequired rule on FirstName property and AddressDetails applies Csla.Validation.CommonRules.StringMaxLength on BuildingName Property.

 

Back to UI.

At runtime, the invalid fields from PersonalInformationUserControl are marked with a red border. This won’t happen for AddressDetailsUserControl invalid fields.

Also, if AddressDetails business object become valid after PersonalInformation business object become valid, the UI won’t be updated. On the other hand, at the business layer level everything works perfectly.  

 

Questions

 

1.      What is the EditForm class purpose?

2.      Why AddressDetailsUserControl invalid fields don’t have a red border?

3.      Why the UI isn’t updated if the business objects change their status?

 

Please find more details in the attached project.

 

Thanks in advance,

 

Costin

 

RockfordLhotka replied on Wednesday, August 01, 2007

This is why I'm writing the Using CSLA .NET 3.0 ebook Smile [:)]

  1. EditForm is a subclass of UserControl that provides some common functionality used by all the edit forms in PTWpf.
  2. The Validator control works against exactly one object: the current DataContext. To get your child objects validated, you need to use a Validator in the list template - in addition to the Validator you use at a higher level to validate the parent object.
  3. I don't understand this question. Are you asking if your button should enable/disable automatically? The answer is yes, but it drives off the business object's IsSavable property, so make sure that's working properly. If you have child objects, remember to override IsValid and IsDirty in the parent.

 

Copyright (c) Marimer LLC