Παρουσίαση με Ετικέτες

XAF: Soft Validation (What’s New in 13.2)
28 Νοεμβρίου 13 05:50 πμ | tolisss | 0 σχόλια   

Our next major release (13.2), updates our Validation Module with more features that come with different behavior rules, such as Warnings and Information. These can be applied to your existing validation rules using code or the Model Editor.

The XAF validation module is a mature and flexible validation system, which allows you to create rules that can validate any business problem, For more information, check out the module documentation.

Suppose we have a Business Object that disallows saving a Customer if the Name property is blank. If this attempted the UI should respond with a “Everybody has a name!” message.

[DefaultClassOptions]

public class Customer : BaseObject {

    public Customer(Session session) : base(session) { }

    [RuleRequiredField("Customer_Name_Required", DefaultContexts.Save, "Everybody has a name!")]

    public string Name { get; set; }

    public string City { get; set; }

    public int Age { get; set; }

}

When an end user tries to save the Customer without a name, XAF will show the Validation Error listview and consequently abort.

image

Creating a warning rule

A common requirement for our Customer class is to warn the end user that, if possible, he/she should provide the Customer’s city. To do this, we need to mark the City property with a  RuleRequiredField. However, this time we have to set the ResultType to Warning as illustrated below.

[DefaultClassOptions]

public class Customer : BaseObject {

    public Customer(Session session) : base(session) { }

    [RuleRequiredField("Customer_Name_Required", DefaultContexts.Save, "Everybody has a name!")]

    public string Name { get; set; }

    [RuleRequiredField("Customer_City_Warning", DefaultContexts.Save, "Provide the City if possible",

        ResultType = ValidationResultType.Warning)]

    public string City { get; set; }

    public int Age { get; set; }

}

When the end user saves the Customer (in runtime) providing a Name and not a City, XAF will again show the Validation Error listview however, this time there will be an extra Ignore action.

image

If the end user executes the Close action, the object will not be saved however if he executes the Ignore action it will be saved. In both cases in the detailview there will be a warning action by the City textbox to draw the end user’s attention.

image

Creating an Information rule

XAF allows you to create validation rules even at runtime using the Model Editor. So let’s say we want to just inform the end user, if he enters a Customer Age not between 10 and 60. This means that we need to use a RuleRangeField rule as illustrated in the next two images.

image

image

When the end user saves a Customer (in runtime) with an invalid Age range, XAF will not display the Validation Error listview at all. However, it will display an Information icon to draw his/her attention to the Age property.

image

Where to see more examples?

You may explore our FeatureCenter application located in your C:\Users\Public\Documents\DXperience 13.2 Demos\eXpressApp Framework\FeatureCenter\CS folder to see a few rules in action.

What about the web?

The validation module as a platform agnostic module works similarly for the web.

image

The soft validation is in its first release (CTP), thus we look forward to your feedback as we get it ready for it’s official release. Let me know what you think.

Δημοσίευση στην κατηγορία: , , ,
UI Annotation using Business Rules
01 Μαΐου 13 11:51 μμ | tolisss | 0 σχόλια   

XAF already provides strong and flexible validation for any object that fits specified Rules with build-in the Validation Module. In this post you can find a sample XAF application which extends the Validation to provide support for Warning/Information messages.

The implementation uses any Validation Business Rule that exists in XAF’s Application Model. Below we see the default ones but its applicable to custom business rules as well.

image

The sample code extends the Application Model of IModelRuleBase and by using one more property like RuleType marks the rule as warning or information as shown:

image

When the Validation occurs this implementation will not raise exceptions for Warning and Information Rules and will change their notification icon accordingly.

Windows

image

Web

image

By default, it is also possible to create business rules that evaluated when an object is changed  by using the ObjectSpaceObjectChanged custom context (see also Contextual Validation Concepts).

To use this RuleType functionality discussed today in your XAF Applications you need to download the sample from RuleType.zip. The functionality is described by just one controller in RuleTypeController.cs which is spanned across the platform agnostic and platform depended projects.

Note: I “borrow” the code for RuleType support from our community project expandframework and for one more time we clearly see how flexible is XAF and how powerful to provide reusable solutions!

P.S.: The original eXpand implementation has code support using a RuleTypeAttribute as well as ListView support and can be found in Xpand.ExpressApp.Validation, Xpand.ExpressApp.Validation.Win and Xpand.ExpressApp.Validation.Web assemblies (See also this discussion in eXpand’s forums).

Δημοσίευση στην κατηγορία: ,
Context programming
06 Δεκεμβρίου 10 07:35 πμ | tolisss | 0 σχόλια   
I ll start this post with a phrase : WE HAVE TO REMEMBER TO NOT REINVENT THE WHEEL . Why I say that? XAF with the help of eXpand   is now a very mature framework. Almost all the tools required for build LOB applications are here. XAF has many ruling engines (Validation,EditorState,Appearence) and eXpand also the same ( AdditionalViewControls , ModelArtifactState , MasterDetail , ConditionalDetailViews). All the above engines provide a way to describe behaviors using rules and they operate over certain Contexts. What is a context some of you may ask. The answer is simple, context means the “when” the rule is going to be evaluated. For example Validation rules have 2 predefined contexts , those are Save,Delete. I am going to give an example of how powerful a context is . Let say we have a Customer-Order relationship and we have 2 cases like the following First record of Customer Orders cannot be deleted. Only the last record of Customer Orders can be deleted So what we need to design the above rules? First

Διαβάστε περισσότερα »

Δημοσίευση στην κατηγορία:
Validation Rule: At least one property is required
03 Ιουνίου 09 01:33 πμ | tolisss | 0 σχόλια   
Today i stump again upon the same problem . I wanted to throw a validation exception only if both of my properties do not have value. So lets create a validation rule for this one. More info on how we create custom validation rules can be found here Validation Module Since we are talking about multiple property values i think we should go with an attribute that is applied to a class and not to a property. Ok first we have to define that both our RuleBaseAttribute and RuleBaseProperties derived classes will implement . public interface IRuleRequiredForAtLeast1PropertyProperties { string MessageTemplateMustNotBeEmpty { get; set; } string Delimiters { get; set; } string TargetProperties { get; set; } } ok that looks nice lets explain what we have here for a bit.

Διαβάστε περισσότερα »

Δημοσίευση στην κατηγορία: , , ,

Search

Go

Το Ιστολόγιο

Ιστορικό Δημοσιεύσεων

Συνδρομές