Exposing Validation Rules to the UI

Exposing Validation Rules to the UI

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


lwmorris posted on Wednesday, February 25, 2009

I'm developing a web app and don't see how to expose some business validation logic to the UI. For example, if last/sur/family name has a maximum length of 64, how would the UI know to set it's textbox.MaxLength property to 64; I don't what to hard code 64 in the UI.

Thanks for any help!

RockfordLhotka replied on Wednesday, February 25, 2009

You can ask the object for its rules, and you'll get back a collection of rule:// URI's. You can then use the Csla.Validation.RuleDescription class to parse those URI's to get at the rule name, property name, parameters, etc.

The method to get the list of rules is on the ValidationRules object, and is accessible inside your business object:

var rules = ValidationRules.GetRuleDescriptions();

To make this available to the UI you'll need to put a public method on your business object.

If you have a custom base class between BusinessBase<T> and your business objects (which I recommend), then you can add this method to your base class, and all your business objects will then expose the value.

 

Copyright (c) Marimer LLC