![]() |
|
#1
|
|||
|
|||
|
Hi,
In the web app I'm developing many of the input fields have multiple validators. I'm organizing my <v:groups> by field. Typically I want to short circuit the validation on the first failing rule. Consequently, not rendering multiple error message per field. What's the best way to do that? I did notice the property FastValidate on the ValidationGroup, but I'm not sure how to set it via xml. Thanks. Cheers, Aeden |
|
#2
|
|||
|
|||
|
I noticed others were having similiar problems, but no sloutions were given so I came up with at least one that interested people can read about
here http://aedenjameson.blogspot.com/200...dators-in.html and use until the next release which looks like will include the necessary schema change. Cheers, Aeden |
|
#3
|
|||
|
|||
|
Hi,
Yea, the code is there but not part of the schema yet (SPRNET-1072) It is a bit of a hack, but you could implement a IObjectFactoryPostProcessor that will check to see if the object is a ValidatorGroup and if so, set the FastValidate property to true. Something like this (I did not test) Code:
public class FastValidatePostProcessor : IObjectFactoryPostProcessor
{
public void PostProcessObjectFactory( IConfigurableListableObjectFactory factory )
{
string[] validatorGroupNames = factory.GetObjectNamesForType(typeof (ValidatorGroup));
foreach (string validatorGroupName in validatorGroupNames)
{
IObjectDefinition definition = factory.GetObjectDefinition(validatorGroupName);
definition.PropertyValues.Add("FastValidate", true);
}
}
}
Try it out, I'd be keen to hear how it goes. I could inclue this in 1.2.1 as some work around until we update the schema in 2.0, but pehraps we are being to strict for the 1.2.1 not introducing *any* schema changes. Cheers, Mark |
|
#4
|
|||
|
|||
|
And that's why you work where you do. Good solution. I tested it out and it does what I need and haven't noticed any immediate side-effects. I, almost universally, desire the behavior on only those groups that target a single property so all I had to do was adopt a naming convention for those groups.
Et Viola! Code:
public void PostProcessObjectFactory(IConfigurableListableObjectFactory Factory)
{
string[] ValidatorGroupNames = Factory.GetObjectNamesForType(typeof(ValidatorGroup));
foreach (string ValidatorGroupName in ValidatorGroupNames)
{
if (ValidatorGroupName.EndsWith("FastValidate"))
{
IObjectDefinition definition = Factory.GetObjectDefinition(ValidatorGroupName);
definition.PropertyValues.Add("FastValidate", true);
}
}
}
Aeden Last edited by aedenj; 04-15-2009 at 07:20 AM. |
|
#5
|
|||
|
|||
|
you should be able to set it via
Code:
<v:group ...>
<property name="FastValidate" value="true" />
....
</v:group>
Erich |
|
#6
|
|||
|
|||
|
I had tried that in my early experimentation with library, but it's not a valid child element of <v:group> so a schema validation exception is thrown.
Cheers, Aeden |
|
#7
|
|||
|
|||
|
I am very sorry, this was my oversight when implementing FastValidate. It is possible to specifiy <v
roperty> on <v:validator> elements but not on <v:group> elements.@Mark: I think we should relax the change policy to "allow 100% binary backwards compatible API changes" I will extend the schema - it is an entirely non-breaking change and in line with e.g. DbC precondition requirements -Erich |
![]() |
| Thread Tools | |
| Display Modes | |
|
|