Spring for .NET Community Forums    

Go Back   Spring for .NET Community Forums > General > Core Container

Reply
 
Thread Tools Display Modes
  #1  
Old 04-09-2009, 03:41 AM
aedenj aedenj is offline
Member
Spring User
 
Join Date: May 2008
Posts: 34
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
Reply With Quote
  #2  
Old 04-14-2009, 05:07 AM
aedenj aedenj is offline
Member
Spring User
 
Join Date: May 2008
Posts: 34
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
Reply With Quote
  #3  
Old 04-15-2009, 04:07 AM
Mark Pollack Mark Pollack is offline
Spring.NET Co-Lead
Spring TeamSpring User
 
Join Date: Sep 2004
Location: New York, NY
Posts: 1,603
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
Reply With Quote
  #4  
Old 04-15-2009, 06:31 AM
aedenj aedenj is offline
Member
Spring User
 
Join Date: May 2008
Posts: 34
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.
Reply With Quote
  #5  
Old 04-15-2009, 10:48 AM
Erich Eichinger Erich Eichinger is offline
Senior Member
Spring User
 
Join Date: Jan 2006
Location: Oslo, Norway
Posts: 1,337
Default

you should be able to set it via

Code:
<v:group ...>
   <property name="FastValidate" value="true" />
    ....
</v:group>
hth,
Erich
Reply With Quote
  #6  
Old 04-16-2009, 02:40 AM
aedenj aedenj is offline
Member
Spring User
 
Join Date: May 2008
Posts: 34
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
Reply With Quote
  #7  
Old 04-16-2009, 09:24 AM
Erich Eichinger Erich Eichinger is offline
Senior Member
Spring User
 
Join Date: Jan 2006
Location: Oslo, Norway
Posts: 1,337
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:10 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.