Only warning, not INVALID! I need "Warning rule".

Only warning, not INVALID! I need "Warning rule".

Old forum URL: forums.lhotka.net/forums/t/1331.aspx


phucphlq posted on Tuesday, September 26, 2006

Hello!

When user change property of business object, I only want to show a waring if new value don't satisfy. How to do?

Example: When user input an empty string, I will show a message but accept and save new value.

Brian Criswell replied on Tuesday, September 26, 2006

Take a look at the error severity feature in the 2.1 beta.

phucphlq replied on Tuesday, September 26, 2006

With a property of business class. I have valid rule(Ex: StringRequired, MaxLenght). This is already in CSLA.

But I need some "warning rule" for that property. Ex: When user input a string that length less than MinLenght, I will show a message to warning then accept and save value. Do CSLA has this function?

Michael Hildner replied on Tuesday, September 26, 2006

phucphlq,

As Brian said, there's a severity level in 2.1. Before 2.1 there was not a severity level, everything is an error and prevents saving.

The AddRule methods are overloaded, and if you don't specify the priority, it defaults to an error. Check out ValidationRules.cs.

You may want to specify the priority in your rule. Specifically, the RuleSeverity enum. 0 = Error, 1 = Warning, 2 = Information.

Hope this info is correct. I'm just getting into 2.1 myself.

Many Regards,

Mike

 

phucphlq replied on Tuesday, September 26, 2006

Thanks. I will read carefully change log. I expect Rocky will make a extent of book and I will buy immediate.

xal replied on Wednesday, September 27, 2006

Michael, you're talkin about priority. The AddRule methods don't allow severity, it's the rule args that do.
So you could inside your rule method change the severity, but if you use the standard csla rules, you might get around the severity by secifying that in the args before adding the rule. Like:

<pseudocode>
Public overrides sub AddBusinessRules
    Dim args as New RuleArgs("myProperty")
    args.Severity = Warning
    ValidationRules.AddRule(Addressof StringRequired, args)
End Sub
</pseudocode>

Since the argument doesn't change from bo to bo (or in instance rules, it always 1 arg per object), the "Warning" should stick unless you do something in one of your rules to change that.
I generally set severity inside my rule method, but I you use rocky's validation routines, you'll have to do it this way.

Andrés

Michael Hildner replied on Wednesday, September 27, 2006

You're right Andrés, sorry about that.

Until the book is available, I've been trying to teach myself 2.1 by going through the code. Got a little confused.

Mike

Copyright (c) Marimer LLC