CNemo7539
06-18-2007, 08:23 PM
First of all please describe what I would like to do.
I have US state dependent validation logic. It's easy to define it, but I also want to be sure that when system will get new state in the business it will not slip through the validation just because there is no rules defined.
So, I decided to use something like following:
<v:any id="PolicyValidator.State">
<v:group when="State == StateId.AZ">
<v:ref name="AZ"/>
</v:group>
<v:group when="State == StateId.OH">
<v:ref name="OH"/>
</v:group>
<v:condition id="UndefinedState.State" test="false">
<v:message id="Validation is undefined for {0}" providers="PolicyValidator">
<v:param value="State"></v:param>
</v:message>
</v:condition>
</v:any>
In the simple words if we get to the bottom of that group, that means something is wrong, and we need to fail.
And I was very disappointed to find that it's got going to work, because in "any" group "when" evaluated to false, essentially skips all processing.
Is there any way to throw message when there is no rules defined. That will be real help in production. The idea is that validator skipped is not the same as processed and returning result.
The simplest solution I see is to change code a little bit to allow validators to be in three states: true, false and disabled/skipped/whatever.
So, groups can distinguish between disabled and real outcome from Validate. I guess it will be not that difficult to implement by let say adding additional parameter to the group, something like account-when
<v:any id="..." account-when="false">...
In the DoValidate() group should check this option and process accordingly.
Because this logic is intended to make checks, might be good reason to call such groups checked.
It's just my suggestion.
I have US state dependent validation logic. It's easy to define it, but I also want to be sure that when system will get new state in the business it will not slip through the validation just because there is no rules defined.
So, I decided to use something like following:
<v:any id="PolicyValidator.State">
<v:group when="State == StateId.AZ">
<v:ref name="AZ"/>
</v:group>
<v:group when="State == StateId.OH">
<v:ref name="OH"/>
</v:group>
<v:condition id="UndefinedState.State" test="false">
<v:message id="Validation is undefined for {0}" providers="PolicyValidator">
<v:param value="State"></v:param>
</v:message>
</v:condition>
</v:any>
In the simple words if we get to the bottom of that group, that means something is wrong, and we need to fail.
And I was very disappointed to find that it's got going to work, because in "any" group "when" evaluated to false, essentially skips all processing.
Is there any way to throw message when there is no rules defined. That will be real help in production. The idea is that validator skipped is not the same as processed and returning result.
The simplest solution I see is to change code a little bit to allow validators to be in three states: true, false and disabled/skipped/whatever.
So, groups can distinguish between disabled and real outcome from Validate. I guess it will be not that difficult to implement by let say adding additional parameter to the group, something like account-when
<v:any id="..." account-when="false">...
In the DoValidate() group should check this option and process accordingly.
Because this logic is intended to make checks, might be good reason to call such groups checked.
It's just my suggestion.