This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I've been diving into Validation within LightSpeed, and have the following questions/suggestions:
a) Is it possible to allow custom validations to appear (and/or specify LightSpeed rules we can hide) on the Properties Window for an entities property? (Rather than having to go through the LightSpeed Model window)? Also, is it possible to update the name of the custom validation rule in the LightSpeed model rather than referring to them as "Custom Validation"? (This is very confusing when we have a few custom validation rules for a specific property).
b) I would like the validation errors expose a "Category" (or "Severity") to the UI. There are a few strategies I would consider: 1) Add the "Category" property to a custom layer supertype for Validation class, and allow setting of the property in the designer. I've not come across any hooks that I can use for this strategy. 2) Derive from each of LightSpeed concrete validation rules, and add a "Category". Unfortunately, the concrete LightSpeed ValidationRules are all sealed. 3) I have considered creating my own layer supertype class to add the Category, and then I could create my own set of "basic" validation rules (ala those provided with LightSpeed), but I would still run into the issue that the designer doesn't treat these are "first-class" citizens (plus, I'd need to be able to hide the LightSpeed ones to save confusion). Additionally, I'd be replicating logic that you guys have written and tested, which would obviously be undesirable.
Any guidance would be appreciated! |
|
|
(a) is not directly possible, but it could be accomplished using designer extension properties and customised templates. For (b) I think (3) would be the only approach that would work at the moment, but as you note this would leave you building a whole parallel structure and having to remember to ignore the built-in validations. However I guess this ties in with your question about getting the rule: if the category could be derived from the rule and we added the rule to the ValidationError, then you could map rules to categories externally to LightSpeed. Or do you need to specify categories on a per-instance basis (e.g. the uniqueness validation on EmailAddress is category Red but the uniqueness validation on ResidentialAddress is category Blue)? Severities are another matter. In LightSpeed, all validation failures have the same severity: they all prevent saving. So if you want to use validations for warnings ('you should fix this but we're not going to make you') then you will need to use something other than LightSpeed validations anyway. |
|
|
Hi Ivan,
What I basically want to do is render the UI different based on different validation rules. For example, should we have the "PresenceValidationRule" in error, I'd like to show this differently (e.g. a blue border) from say a uniqueness rule that is error (e.g. a red border). As you note, this is different from "Severity", which we can safely ignore.
Back on the subject of question (a), is it possible to suggest an enhancement request for custom validation rules? When you get a number of custom rules, the LightSpeed Model window is very confusing. It is impossible to know which rule is which. I'd love to have text describing the rule (i.e. "No Whitespace Validation" rather than "Custom Rule"). Of course, you can determine the rule once you click on it (and if you have your properties window open), but i feel this enhancement would be beneficial. Would it also be possible to be able to right click on the Validation folder and have the options of "Add New Custom Validation"? Having to know to right click the property ("Code" in the picture) is a little unintuitive.
Thanks again for your help! |
|
|
Great suggestions! Thanks! I've implemented what I can and it will be in the next nightly build. * ValidationError has a new RuleType property which returns the type of rule that failed. You can map that in your code to a category or UI element. (I believe the type rather than the rule instance will suffice; let me know if not.) Note that RuleType can be null if the validation failure didn't originate from a rule (specifically, the 'associated entity has errors' error), or if the rule is a custom one which doesn't observe the next point. * To support the above, there is now an overload of ValidationContext.AddError which takes the ValidationRule that failed. Your custom validations should call this overload if they want to provide RuleType info. If they do not do this then RuleType will be null. * Custom validations in the designer now show the attribute text in the LightSpeed Model Explorer (or "Custom Validation" if the attribute text hasn't been filled in yet). If this isn't descriptive enough, there is also a Display Name setting to override the Explorer display. The display name does not affect the generated code -- it's purely to improve explorer navigation. One bit of bad news though: [quote user="BradL"]Would it also be possible to be able to right click on the Validation folder and have the options of "Add New Custom Validation"?[/quote] I wish it were! Unfortunately the Explorer context menus are created by Visual Studio. Why the VS folks decided to make them work this way is beyond me, but it is significant effort to modify how they work and we cannot currently justify that effort in terms of the improvements it would deliver. |
|
|
Wow! Thats fantastic. Thanks again for your help!! |
|