We are in the process of finding a way to add client-side
validation to webform controls which are bound to CSLA business objects. This
validation will need to be driven by the rules specified within the business
object. Could you please tell me if the approach we're taking is viable,
and if there might be a better way to do it?
The plan thus far, involves a UI class that would be included into the custom
controls we are developing. As each control requiring validation is added
to the page we would query the BO and derive its validation rules for the
applicable property. Once this is done the class returns new webform
validation controls, for the custom control to place as it sees fit.
When attempting to implement this, I ran into a snag querying the validation
rules from the BO... the class containing the information about the rules
(RuleMethod) is internal, and is contained by a generic List object. The
net effect being, I've been unable to cast the property's list of rules as
anything other than Object which doesn't do me much good at all.
I would appreciate any suggestions.
Thanks,
Shayne
Hi Shayne,
I don't know if this is the professional way do it. In my case, I used AJAX (that calls a webservice) to do the field validations in the WEB-UI.
In my case the webservice returns a string: The possible values of my string are: a.) True - if there where no rules broken b.) False,Broken rules description.<br>
The process of the webservice: a.) it instantiate the BO that contains the rules b.) assisgned the BO property with the parameter specified in the web method c.) checked BO.IsValid if it fails, loops in the broken rules collection in the BO and rturn the broken rules descriptions otherwise it returns True. d.) then I use span to display the broken rules in the WEB UI
I hope I was able to shed a little idea.
shaynev:
... is simply adding a public property to the BO with a summary of validation rules.
I think this would be an excellent addition to the framework, and not just for the reason you mention.
It would enable Documentation generators or help screens to display a list of all business rules and the potential error messages that go with them.
Anyone responsible for QA would kiss the ground you walk on if you provided them with this information.
In addition, if there was a link between the rule and the business explanation for the rule - I'm talking about complex business logic, not (max length = 50) - the UI could allow the user to press a "Why?" is this a rule button and get the business justification for the rule.
david.wendelken:shaynev:
... is simply adding a public property to the BO with a summary of validation rules.I think this would be an excellent addition to the framework, and not just for the reason you mention.
It would enable Documentation generators or help screens to display a list of all business rules and the potential error messages that go with them.
Anyone responsible for QA would kiss the ground you walk on if you provided them with this information.
In addition, if there was a link between the rule and the business explanation for the rule - I'm talking about complex business logic, not (max length = 50) - the UI could allow the user to press a "Why?" is this a rule button and get the business justification for the rule.
Of course a lot of time has passed since this thread started and today. CSLA .NET does now have the concept by which you can ask an object for its rules. This is in version 2.1, with some slight enhancements in 3.0.
You can use these rule descriptions to generate UI code or behavior in various ways.
Recently Chris posted some code along this line (http://forums.lhotka.net/forums/thread/17870.aspx), and others have done work in this area as well.
Here is a clever framework that does what you are looking for, It takes a collection of broken object validations and maps them to web controls in a web form. Broken validations are diaplayed via a centralized mechanism that sets the style of relevant web controls. A popup is displayed on focus or mousover.
http://www.spikesolutions.net/ViewSolution.aspx?ID=49834d35-991c-4d15-ab6c-a79426220274
Copyright (c) Marimer LLC