Sunday, October 4, 2009

Thoughts on John Papa's DataForm MSDN Article

A nice article on using the DataForm. Documentation is lacking for this control, and most blog posts are out of date, as last minute changes were made before it was released.

Is it good to use the CustomValidator attribute? Stuff I've done recently is not using attributes. It means the validation checks are in the property setters.... Is this good? It keeps things contained, but maybe the validation doesn't really belong there.....

It is using databinding directly to the Employee model. Properties such as Age are integers, so if a character is entered, the model retains the old value and appears internally to be valid, even though the view is now in an invalid state, which is bad. Also, it means the only error message you can give the user is "Input string is not in a valid format". I think it's better to have a ViewModel, bind only to it, and have properties such as Age defined as a string so that any value can be set, and then checked for validity. Means the View and the ViewModel are kept in sync, and you can give the user customised error messages.

I'd hate to see the look on our UCD guys' faces if I had to tell them I couldn't give them a custom error message if an alpha was typed into a numeric field... Probably get more of that "that's crap, it's easy to do in Flex...." ;-)

No comments:

Post a Comment