views:

437

answers:

2

Hello Everyone

I am looking for a best-practise approach on how to do UI-validation in a model-view-presenter architecture.

I need to validate some forms with a lot of controls, and to make it easy for the user I store all errors or warnings with a reference to the control in a Log which is displayed to the user afterwards, so he can jump right away to the control he has to fix. This is done in the view-part, which is actually wrong since validation should take place in the presenter in order to exchange the view.

The problem for me of doing this validation in the presenter is that it is not just checking if provided values are wrong, it also needs to check if radiobuttons have been checked which enables a textbox, which then has to contain some text for example. I was thinking of using the BindingSource in the presenter since its reflecting the ui-changes and is visible to the presenter. But I am not sure if this is the right way to go (and I think its kind of uggly)?

By the way: the validation takes not just place before I write to the database, it already takes place while the user is working on the forms.

Could anyone think of a good way of doing this? Thanks in Advance

A: 

Perhaps making use of a PreProcess/PostProcess function would come in handy, something like:

if (PreProcess)
{
    ProcessInformation;
}
PostProcess;

PreProcess/ProcessInformation could populate some sort of condition table (perhaps a hashtable) which PostProcess then checks and handles accordingly.

James
+1  A: 

We finally found a solution. It will be done as I expected, using the DataSet in the presenter which is processed by different validator classes (one for each of our "pages"). The most difficult part is, when controls depend on each other (but in the end its just checking if values are set in the DataSet). Currently it is not possible to jump to the control to fix errors but this will be added later via Reflection by passing the name of the control to the LogEntries and the view can then figure out where this control is.

lostiniceland