Results 1 to 7 of 7

Thread: Short Circuting Validator Groups

  1. #1
    Join Date
    May 2008
    Posts
    35

    Default Short Circuting Validator Groups

    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. #2
    Join Date
    May 2008
    Posts
    35

    Default

    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. #3
    Mark Pollack is offline Spring.NET Co-Lead Spring TeamSpring User
    Join Date
    Sep 2004
    Location
    New York, NY
    Posts
    1,683

    Default

    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);
        }
      }
    }
    You could configure this post processor to only set that FastValidate property to true for specific ValidatorGroups as the PostProcessor can be configured via DI as any other object.

    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. #4
    Join Date
    May 2008
    Posts
    35

    Default

    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);
                    }
                }
            }
    Cheers,
    Aeden
    Last edited by aedenj; 04-15-2009 at 07:20 AM.

  5. #5
    Join Date
    Jan 2006
    Location
    Cambridge, UK
    Posts
    1,340

    Default

    you should be able to set it via

    Code:
    <v:group ...>
       <property name="FastValidate" value="true" />
        ....
    </v:group>
    hth,
    Erich

  6. #6
    Join Date
    May 2008
    Posts
    35

    Default

    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. #7
    Join Date
    Jan 2006
    Location
    Cambridge, UK
    Posts
    1,340

    Default

    I am very sorry, this was my oversight when implementing FastValidate. It is possible to specifiy <vroperty> 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •