views:

32

answers:

2

I'm fairly new to Silverlight and RIA. However, we're developing an app with a SL frontend using WCF/RIA to connect to our service layer. We're using the mvvm pattern so that may play into this as well.

I have a particular dataform where I use commanding to hook the EditEnding event of the dataform. In EditEnding, I call my Service to save the edited object. The service performs some heavy duty validation on the object and currently throws exceptions which I trap in my viewmodel and display with MessageBox.

I want to display those exceptions as validation errors rather than displaying them with messagebox. I've seen a few articles that talk about SL4s new INotifyDataErrorInfo and maybe that is a solution; but I'm a bit confused as to how that is actually implemented. The other thing is that I get the impression that INotifyDataErrorInfo is used to cause "immediate" property validation (of a single property at a time) as opposed to allowing one to validate an entire object in the service layer when the user presses the Submit button.

One requirement I have due to our users and their high latency issues, is that the app not be too chatty. So, I don't want the client making calls to the service for each property being edited in the dataform.

Can anyone shed some light on how I can accomplish this?

Thanks in advance!

A: 

Without seeing more how your viewmodel command interacts with your business object and how you want to display the errors then this is my suggestion...

If you want to display a well formed set of errors on the view when you catch the validation errors from the command execute method add them to an observable collection that you can bind to on the view. This could simply be a listbox bound to the collection and when you try to save the next time you can clear the collection.

As for INotifyDataErrorInfo it really is for simple validations and for quick responses since it will be invoked by the UI every time a bound property changes so not a good place to call out to a service over the network.

HTH

aqwert
Thanks for your reply. Is there a way to add these exceptions to the validation errors that are already being displayed in the dataform ... the validationerrors list?
RHarris
A: 

with INotifyDataerrors errors are displayed on the screen WHEN YOU WANT. That is as soon as your Vie Model raises an event for notifying the interface that a new errors has been discovered.

Unluckly Rias services do implemnt INotifyDataErrors for you, and they use just errors coming from data annotations. Thus, if you want to use Ria services you need to write custom data annotations to evaluate all errors. There are also data annotations at class level. You can validate anyrthing with data annotations. Moreover, if you don't give a .share.cs extension to this data annotations they will be only used on the server side, and not on the client... For more infos, pls read the data annotations series of posts on my blog here. If you want to use exception pls use my Validation toolkit for WPF and silverlight instead of Ria service. It is available for free on codeplex here.

Francesco Abbruzzese