Client-Side Webform Validation tied to Business Objects

Client-Side Webform Validation tied to Business Objects

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


shaynev posted on Thursday, June 08, 2006

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

glenntoy replied on Thursday, June 08, 2006

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.

ajj3085 replied on Friday, June 09, 2006

I think that validation is just one of the issues with Web forms; you typically end up duplicating the business rules in the UI.  I usually end up using the validators, because the idea is to give the web user a 'richer' experience.

While I understand the need for web applications, I think using at stateless web server / broswer combination as a UI is a horrible solution to the problem.  Its a shame Java didn't take off more for this... it would be nice if MS tried to position .Net to fill in that gap (by producing runtimes for non windows computers).

Andy

shaynev replied on Monday, June 12, 2006

Thank you for your responses.

As we want to do the validation without a postback (ideally), it does look like the right way to go is the validator controls.  The thing is, we want to be able to have them created on the fly (based on the validation settings of the BO) so that we only have one place we need to assign the validation, and the wireup is minimized.

Shayne

ajj3085 replied on Monday, June 12, 2006

Well, please post your solution here, as I'm sure quite a few people would like to generate the validators on the fly, including me.

Andy

shaynev replied on Monday, June 12, 2006

I'll be sure to do so once I get it figured out.

Right now I'm still fighting with getting the information through reflection, though I'm not sure if ultimately it'll work.

Another avenue that may be more fruitful, and would not require the use of reflection, is simply adding a public property to the BO with a summary of validation rules.  I've been veering away from this, as we'd prefer to keep the BO's as close to the original design as possible, but since we'll already be adding in a custom logging object, and building templates for the BO's we should have a good opportunity to do it.

If anyone has any suggestions about how a class using reflection can get the information out of the List<RuleMethod> object when the RuleMethod class has restrictive permissions, I would love to hear them.

david.wendelken replied on Wednesday, June 14, 2006

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.

 

 

bobhagan replied on Wednesday, June 14, 2006

I have no idea on first glance whether this fits with csla but look at this:

http://www.ftponline.com/vsm/2006_06/magazine/features/smichelotti/

(The next aticle cited is one of Rocky's)

bob hagan

RockfordLhotka replied on Tuesday, October 02, 2007

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.

crackcode89 replied on Tuesday, October 02, 2007

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