Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

Validation - How to highlight invalid properties when the View is shown

$
0
0

This example demonstrates, how to check rules when the View is activated, or the View's object is changed. For that purpose, the ImmediateValidationController is implemented. To avoid checking these rules when the business object is saved or deleted, their context is set to Custom.

Question Comments

Added By: Robert Emslie 1 at: 6/6/2014 6:00:21 AM    

This controller causes serious performance issues where validation requires database reads for uniqueness etc.

Added By: Anatol (DevExpress Support) at: 6/9/2014 9:46:37 AM    

This behavior is expected, taking into account the ImmediateValidationController's implementation. It checks validation rules on each ObjectChanged event, and thus, if these rules require searching in the database, performance may be affected. To improve performance, do not check such rules on ObjectChanged. Either do not subscribe to the ObjectChanged event in ImmediateValidationController at all, or declare rules that should be checked on ObjectChanged in a different context, and only check this context in the ObjectChanged event handler.

Added By: Vekrasoft at: 8/5/2014 6:07:42 AM    

Hello,

Thanks for this example. I've implemented it and changed it to work with a different context.
We use the 'OnChanged' context to the rules and in this controller we call the ValidateAllTargets function with this context.
This works fine if a validation rule ContextIDs property is exactly set to 'OnChanged' but now we want to connect it to more than one context so changed this to 'Save, OnChanged'. This should work according your documentation. But after this change the rules are not checked anymore. When validating in the Save action, the rules are validated as expected.

Could you please help? Thanks.

Added By: Vekrasoft at: 8/5/2014 7:22:44 AM    

Hi, I looked into the source code and found out that we need to split the different contexts in the string with te ';' separator in stead of the ',' separator. My bad. Works now as expected. Thank you.

Added By: Anatol (DevExpress Support) at: 8/5/2014 7:36:17 AM    

I am happy to hear that you have found a solution. Please let me know if there is a documentation topic that contains incorrect information about the separator.

Added By: Hari Setyawan 2 at: 8/18/2015 12:09:46 AM    

I just implement this example together with audit trail. But I got an error on :

if (resultsHighlightController != null) {
               RuleSetValidationResult result = Validator.RuleSet.ValidateAllTargets(ObjectSpace, targets, DefaultContexts.Save);
               if (result.ValidationOutcome == ValidationOutcome.Error || result.ValidationOutcome == ValidationOutcome.Warning || result.ValidationOutcome == ValidationOutcome.Information) {
                   resultsHighlightController.HighlightResults(result);
               } else {
                   resultsHighlightController.ClearHighlighting();
               }
           }

And I solved, If modified with this code :

if (resultsHighlightController != null && targets != null)

Thanks,
Hari Setyawan


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>