views:

45

answers:

1

As an example, say I have a single domain object with 100 properties. In my UI I need complex validation of the style:

If A = 1, show controls B, C, D. B is required, C is not, and D is not required must be less than 30 if it is populated.

If A = 2, show controls B, D, E. B is not required, D is required but has no limits, and E is not required.

If A = 3, show controls B, E, F. B is required and must be more than 10, E is required, F is not required.

If B = 3 and F = 5, then show control G, but only when A = 3.

You can see my problem here. The relationships between the properties are hideously complex, with validation changing dependant on earlier values and in combination with other values.

How have people modelled and handled this in the past? Validation does not need to very often, but a config/xml-based solution would probably be best.

Thanks.

+1  A: 

You could project this gigantic domain object into smaller objects containing only the subsets of properties needed and name them according to the scenario they are describing. It's creating some sort of ViewModel if you will.

There has to be a specific use case for each case of A = "X" or B = "Y" etc. If you are splitting things up you can define validation rules per ViewModel. Those ViewModels could also contain the visible/hidden settings for your controls.

Zebi