HOW TO Expose Child Broken Rules on the Parent

HOW TO Expose Child Broken Rules on the Parent

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


Mr.Underhill posted on Thursday, June 15, 2006

I have a parent object that contains a child object.  The child object has its own Broken Rules Collection.  If my Parent is invalid, it might be because the child is invalid.  If I ask my Parent for the BrokenRules, the BrokenRules on the parent might be empty (because the broken rule is on the child).

 

HOW TO Expose Child Broken Rules on the Parent?

 

Thanks

=

Pradeep replied on Thursday, June 15, 2006

What version of CSLA are you using? For 1.5 you have to write your own function to get the broken rule's list. Tere is an implementation provided by Peter in ActiveObjects.  In that he loop's through each child object and builds an arraylist of broken rules. Take a look at that.

HTH

jwooley replied on Thursday, June 15, 2006

I posted an extraction of Petar's implementation on the old forum a while back. You may be able to search for it.

I'm curious, do you need the actual rules or just to know if the children are valid? If it is just the later, your parent object should override IsValid (and IsDirty) to do the following:

Return MyBase.IsValid AndAlso ChildCollection.IsValid.

Each level of the tree should only be responsible for the level directly below it. Parents should not be responsible directly for the grandchildren. If the children can report for them and their children, everything should cascade nLevels gracefully.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx

Mr.Underhill replied on Thursday, June 15, 2006

Thanks for your feedback, I'll take a look at Peter's work.  I'm concern about getting access to the broken rules itself.  The IsValid trick is also really important, and that I'm using already.

 

 

Thanks

jdelano replied on Thursday, August 10, 2006

I'm also looking to retrieve the BrokenRules string from the parent object, but I'm using CSLA 2.0. Has anything changed in that regard since 1.5?

Thanks,

John

RockfordLhotka replied on Thursday, August 10, 2006

No, nothing has really changed in how broken rules are exposed to the UI from 1.53 to 2.0.

jdelano replied on Thursday, August 10, 2006

I've basically got one root object with lots of children collection objects displayed across multiple tabs on a tabbed interface, and it would be nice if the user knew approximately where the error was, so all I really want to do is give the user a hint at where to look. In other words, I really don't care what specific errors occurred on a specific grandchild object, but I do want to know whether or not a specific child object has invalid grandchildren. Does that make sense?

Since the number of child collections is static within my parent object, I know that I could expose a GetBrokenRulesString property and manually add my own "Error in: xyz collection" string for each of the child collections that are not valid. So, my question is whether or not there is any way to iterate through all the child collection classes within a given parent, or do I have to do something like this...

Public Property GetBrokenRulesString() as String
   Get
      Dim temp as String = ""
      If Not Child1.IsValid Then
         temp &= "Error in Child1" & vbCrLf
      End If
      If Not Child2.IsValid Then
         temp &= "Error in Child2" & vbCrLf
      End If
      ...
      Return temp
   End Get
End Property

I'm guessing the answer is going to have something to do with reflection (which I'm fairly new at), so could someone provide some example syntax?

Thanks,

John

Copyright (c) Marimer LLC