RiaServicesValidation

There are 12 entries for the tag RiaServicesValidation
RIA Services Validation: Available on GitHub

I’ve gotten quite a few requests for the source code behind the RIA Services Validation blog post series.  I am pleased to announce that the code is now published on GitHub. http://github.com/jeffhandley/RIAServicesValidation Within that repository, you’ll find: RudeValidation.Web/Models – Server-side model classes RudeValidation.Web/Validators – Custom validators including CompareValidator, ConditionallyRequired, and DateValidator RudeValidation/Views – Sample screens showing the validation in action RudeValidation/ViewModels - Where you’ll find the sample ViewModel as well as the very simple ViewModelBase If you’re not familiar...

posted @ Tuesday, September 6, 2011 11:50 PM | Feedback (2)

RIA Services Validation: ViewModel Validation with Entity Rules

For those of you familiar with the ViewModel (or MVVM) pattern, you are likely also familiar with a typical pain point regarding validation: you often need to duplicate your entity validation metadata onto your ViewModel classes.  This can lead to burdensome dual maintenance of your validation rules, and it can seem very frustrating that with the server to client metadata propagation that RIA Services offers, your ViewModel classes are left dangling out there for you to manage yourself.  In this post, I’ll illustrate a utility I created that allows a ViewModel to assume validation metadata from model classes or properties,...

posted @ Tuesday, September 6, 2011 11:31 PM | Feedback (5)

RIA Services Validation: Video Tutorials (in VB)

Not too long ago, a gentleman named Bill Burrows (a VB MVP) contacted me and asked for permission to use content from my blog to create a video tutorial series on RIA Services Validation.  I was really flattered by this and gave him my permission.  I apply a Creative Commons Share-Alike license to the content on my blog, so Bill could have really done this without my explicit permission, but I do appreciate that he asked.  I simply requested that he respect the Share-Alike and Attribution portions of the license. Today, Bill sent me an update to let me...

posted @ Friday, November 19, 2010 9:43 PM | Feedback (0)

RIA Services Validation: Using ValidationContext (Cross-Entity Validation)

In our last post, we learned how ValidationContext can be used to provide and consume state and services for validation methods to use.  Now, let’s take a quick look at how validation methods can actually use this information.  I’m going to include a bunch of code in this post, and I will rely on the code to be rather self-explanatory. Property-Level Validation In this property-level validation example, we need to validate that the location entered for a meeting is a valid location from our database.  We want this to work both on the server and on the client,...

posted @ Monday, October 25, 2010 1:56 AM | Feedback (20)

RIA Services Validation: Providing ValidationContext

Throughout this series on RIA Services Validation, I’ve mentioned and shown ValidationContext several times.  In this post, we’ll learn about the purpose of ValidationContext, what types of context it can provide, and how it integrates with RIA Services.  This will allow us to explore further topics such as cross-entity validation and open the door for other advanced validation scenarios. ValidationContext Purpose Although ValidationContext exists within the System.ComponentModel.DataAnnotations assembly in both .NET 4.0+ and Silverlight 3+, the class was introduced by the RIA Services team.  While designing the RIA Services validation system, we considered scenarios where validation logic is...

posted @ Monday, October 25, 2010 12:49 AM | Feedback (7)

RIA Services Validation: Entity-Level Validation

In my last post, I went over some cross-field validation scenarios and provided some sample code, including a CompareValidatorAttribute.  We’ve now covered single-field validation and cross-field validation, but there’s yet another level of validation supported by RIA Services—Entity-Level validation.  As you’ll see in this post, entity-level validation is very similar to what we’ve already seen. Entity-Level Validation Declaration Your entity types can declare entity-level validation using either the [CustomValidation] attribute approach where a custom validation method is supplied, or by having an attribute that derives from ValidationAttribute.  Either way, to indicate that a validation rule applies at the...

posted @ Tuesday, October 12, 2010 1:31 AM | Feedback (7)

RIA Services Validation: Cross-Field Validation

I frequently hear questions about how to perform cross-field validation in RIA Services.  Before thoroughly covering this topic*, I wanted to be sure to go through some simple scenarios, show how to use CustomValidationAttribute, how to derive from ValidationAttribute, explain how validation rules are propagated to the client, and what triggers the validation.  Hopefully by now, you’re getting pretty comfortable with the validation framework and you’re ready to explore some more examples. * Perhaps you noticed that I snuck a reusable cross-field validator into the Custom Reusable Validators post—it’s a rather useful ConditionallyRequiredAttribute. In this post, I’m going...

posted @ Sunday, October 10, 2010 1:29 AM | Feedback (4)

RIA Services Validation: Validation Triggers

My goal with this blog post series is to provide an end-to-end tour of how RIA Services validation works and how you can leverage its capabilities to build rich, responsive applications.  A key factor for making the most of validation is fully understanding when and how RIA Services invokes your validation rules.  Awareness of the various validation triggers will help you implement your validators so they are fired as you expect, when you expect.  In this post will dig into the RIA Services codebase and identify every place where entity validation is invoked. Client-Side Validation Property Setters –...

posted @ Wednesday, October 6, 2010 3:48 AM | Feedback (2)

RIA Services Validation: Attribute Propagation

Since the beginning of the RIA Services project, a primary tenet was to propagate validation rules defined on the server up to the client, integrating the validation directly into the Silverlight UI.  This came to fruition with RIA Services v1.0 and you can in fact apply an attribute to your model on the server and automatically get instant client-side validation of data entry on even the simplest of Textbox controls.  In fact, some validation rules are inferred from your data model directly.  This is a feat that many other frameworks have attempted to accomplish, but I believe RIA Services has...

posted @ Thursday, September 30, 2010 2:37 AM | Feedback (2)

RIA Services Validation: Custom Reusable Validators

We just covered Custom Validation Methods, where we learned how to use CustomValidationAttribute to invoke a static (VB: Shared) method to perform validation.  Let’s talk about an alternate approach to custom validation though: creating custom, reusable validators by deriving from ValidationAttribute.  While it’s true that the custom validation methods used by [CustomValidation] could certainly be reusable, I tend to think of that approach as a light-weight way to call specific business logic routines for validation.  The approach we’re about to see is what I use when I’m creating an inventory of validators to be reused throughout my project(s). Deriving...

posted @ Sunday, September 26, 2010 3:39 AM | Feedback (7)

RIA Services Validation: Custom Validation Methods

In our last installment, we learned about the standard validators that ship in the System.ComponentModel.DataAnnotations assembly.  RequiredAttribute, RangeAttribute, StringLengthAttribute, and RegularExpressionAttribute all derive from ValidationAttribute and cover many common validation scenarios.  Every system has its own business rules though, and therefore it’s imperative that RIA Services allows you to create custom validators to implement your own logic.  Moreover, your custom error messages must plug into the same framework that powers the standard validators.  To address this requirement, we added CustomValidationAttribute. Using CustomValidationAttribute to Invoke a Method System.ComponentModel.DataAnnotations.CustomValidationAttribute allows you to easily redirect a validator to a method you’ve...

posted @ Saturday, September 25, 2010 11:12 PM | Feedback (2)

RIA Services Validation: Standard Validators

RIA Services offers powerful features for flowing validation from your entity model all the way up to the Silverlight UI.  In fact, flowing your validation rules from the server into your form controls was one of the primary tenets of RIA Services V1, and our team did the work of getting validation integrated deeply into Silverlight, long before RIA Services was released.  In this post we’ll take a look at the standard validators that are offered. System.ComponentModel.DataAnnotations.ValidationAttribute RIA Services employs the ValidationAttribute class from System.ComponentModel.DataAnnotations for defining validation rules on your entity model.  ValidationAttribute itself is abstract (VB:...

posted @ Wednesday, September 22, 2010 3:16 AM | Feedback (4)