1.53 Not getting IsValid value on child with AllRules

1.53 Not getting IsValid value on child with AllRules

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


esteban404 posted on Monday, June 19, 2006

I have a business base object with several children each of which is bound to a grid and included in the overriden IsValid property on the parent. When testing it, a broken rule will show in the list box control for the parent object normally. Child objects, OTOH, place an error icon on the ofending row in the grid, but no rule is added to the list. The icon is tiny, so it needs to be in the list, too.

I noticed a problem when the save button would not disable when there's an error even though I bound the save button to th IsValid property of all the members. This is the main problem: the button should not be enabled.

I'm using the GetAllBrokenRules method of the AllRules class added to CSLA 1.53 release. I don't think I ****ed it up, but it's not working

I added the following to the Parent BO class:
public
override CSLA.BrokenRules.RulesCollection GetBrokenRulesCollection()
{
     return AllRules.GetAllBrokenRules(this);
}

I stepped through the binding and it seems OK, but still doesn't return IsValid = false for the child. I also added a check box bound to the IsValid property of the collections and they don't fire.

What did I mess up?

_E

RockfordLhotka replied on Tuesday, June 27, 2006

This is, for better or worse, the expected behavior. IsValid cascades up (assuming you follow the code templates from the book), but there is no automatic mechanism by which broken rule descriptions are combined from the children up into the parent.

In other words, if you are finding IsValid is wrong then there's a bug in your object code (you probably aren't overriding IsValid at the parent level). But if you are looking for consolidated broken rules descriptions you'll have to derive your own solution, because the framework doesn't do this.

The reason the framework doesn't do this, is because I am not sure how to reflect the values in a meaningful way - at least not that would work with data binding. The child collection is represented as a single property at the parent level, so all the child (and grandchild, etc.) rules would need to be combined into a single string value that would be returned for that one property. It is not clear to me how you could hope to represent all the errors from an entire object graph in a single string?

On the other hand, you could construct a UI component/control that could do this in a meaningful way. Every BusinessBase-derived object implements IDataErrorInfo. It wouldn't be terribly hard to create a control (tree control perhaps?) that walked down your entire object graph to pull out the error text for each object (using the Error property) or even each property (using the Item property). It would be up to you to display these in a meaningful manner, but at least you'd have access to the detailed information about which objects/properties are not happy.

esteban404 replied on Wednesday, June 28, 2006

Thanks, Rocky. I read all the posts about IsValid and its designed behavior, so this was no surprise. It's was tough find a specific resolution in all the posts. There are so many great solutions.

I solved it by passing the strings from the broken rules collection up the chain and eventually into the BO parent. Then I display the strings in the list box. My BOs don't use ActiveObjects (yet), but I see the behavior is a bit better with AO than what I did.

The IDataErrorInfo is working fine every where, but my users aren't paying attention, so I've changed the behavior to catch their attention and turn off the Save button when any part of the object is not valid. Since I've been sentenced to being all things to all aspects of programs from DBA to user, it's within my power to do sneaky things to keep it on time. Everything is well documented, of course! Wink [;)]

_E

Copyright (c) Marimer LLC