UI Annotation using Business Rules

XAF contains several kinds of modules, one of which is a Validation Module. Validation can be applied to the content of XAF objects when specific rules are applied to the Validation Module. In this post you can find a sample XAF application which extends the Validation to provide support for Warning/Information messages.

Today’s implementation can be used by any Validation Business Rule that exists in the XAF’s Application Model. Displayed below is the default list of these rules, applicable to custom business rules as well.

image

The sample code extends the Application Model of the IModelRuleBase. By using one more property like the RuleType, the Application Model marks the rule as a warning or as information shown below:

image

This will not raise exceptions for Warning and Information Rules when Validation occurs, but will change their notification icon accordingly.

Windows

image

Web

image

HOW TO APPLY THIS GREAT FUNCTIONALITY TO YOUR PROJECT?

  1. Download  RuleType.zip and open it in VS.
  2. Copy its only one Controller located in the RuleTypeController.cs and spanned across three modules to your own platform agnostic and platform depended modules (Win/Web).

    image
  3. Hit F5 and profit!

Note: I “borrowed” the code for RuleType support from our community project expandframework I hope that this blog demonstrated once again just how flexible and powerful XAF is when it comes to providing reusable solutions!

Subscribe to XAF feed
Subscribe to community feed

13 comment(s)
Wietse

This is great!

Isn't this some nice functionality for the 'standard' version of XAF?

2 May, 2013
Apostolis Bekiaris (DevExpress)

Thanks for the feedback Wietse, we already have this suggestion registered www.devexpress.com/.../S90945.aspx. Make sure you follow it to get notified for updates

2 May, 2013
Chris Royle (LOB)

Thanks Tolis, I'm going to have a play with this a bit later today. +1 to having this functionality as standard in off the shelf XAF.

2 May, 2013
Chris Royle (LOB)

Hi Tolis

Using the example app, if I create a new record with Test Info, and Test Warning empty, and select the Validate action, the icons display as errors. Saving turns these into the correct icons.

ditto if I open an existing record, and pressing validate.

Chris

2 May, 2013
Chris Royle (LOB)

Hi Tolis

Here's a scenario:

I have a class with an Email property. There are two rules against this - a information that an email address is useful, and an error which validates an entered email against a regex.

Currently, if you save the class, the information icon shows. Great. Now if you key an invalid email address validation fails, by the information icon remains when this should be showing the error icon.

This can be corrected in Win RuleTypeController by using the following code change:

protected override Dictionary<PropertyEditor, RuleType> CollectPropertyEditors(IEnumerable<RuleSetValidationResultItem> result, RuleType ruleType)

   {

     var propertyEditors = base.CollectPropertyEditors(result, ruleType);

     foreach (var keyValuePair in propertyEditors)

     {

       BaseEdit editor = keyValuePair.Key.Control as BaseEdit;

       if (editor != null)

         editor.ErrorIcon = CreateImageFromResources(keyValuePair.Value);

     }

     return propertyEditors;

   }

2 May, 2013
Apostolis Bekiaris (DevExpress)

Thanks for your fix Chris I already update the sample with it. Also I used the following

var ruleTypes = Enum.GetValues(typeof(RuleType)).Cast<RuleType>().OrderByDescending(type => type);

in base controller

2 May, 2013
Apostolis Bekiaris (DevExpress)

I update the sample once more with listview support, however the validation action still is not supported. Feel free to share with us in case any of you manage to support it.

2 May, 2013
Chris Royle (LOB)

I don't know if you're aware Tolis, but the example code does not have Specific Version = false for DevExpress.ExpressApp.Validation.v12.2.

2 May, 2013
Apostolis Bekiaris (DevExpress)

Thanks again Chris! fixed as well

3 May, 2013
Chris Royle (LOB)

Another one Tolis:

OnViewControlsCreated exceptions when faced with a non GridListEditor - e.g. a TreeListEditor.

Code should read as follows:

protected override void OnViewControlsCreated()

   {

     base.OnViewControlsCreated();

     GridListEditor gridListEditor = this.ListEditor as GridListEditor;

     if (gridListEditor != null && gridListEditor.GridView != null)

       gridListEditor.GridView.CustomDrawCell += GridViewOnCustomDrawCell;

   }

7 May, 2013
Apostolis Bekiaris (DevExpress)

Thanks Chris!

sample updated again.

10 May, 2013
Diego Mondragon 1

I add the controller in the agnostic module and I receive an error on the next lines:

protected void ValidateControlValueChangedContext(object currentObject) {

           Validator.RuleSet.ValidateAll(currentObject, new List<object> { currentObject }, ObjectSpaceObjectChanged);

       }

the metod ValidateAll, requiere 3 parameters, what must I change to test this solution?

24 June, 2013
Apostolis Bekiaris (DevExpress)

You code is outdated due to 13.1 breaking changes. Get the latest version of the class from http://goo.gl/bTlx9

24 June, 2013

Please login or register to post comments.