CompositionType.And with MessageTemplate

Topics: Validation Application Block
May 1, 2009 at 12:11 PM
Edited May 1, 2009 at 12:11 PM

I have this code defined (EntLib 3.1)


ValidatorComposition(CompositionType.And, MessageTemplate="Cannot be empty. Must be 1..100 characters")]
StringLengthValidator(1, 100,MessageTemplate="z")]
public string LetterDescription

My question is how is the MessageTemplate used in an AND.  I was expecting that I would see "Cannot be empty. Must be 1.100 characters" if both tests return TRUE and the messages from both validators would be replaced by this one message. Is that not how this works?

I know they are both returning true because I get


Leaving out the MessageTamplate in the two validators makes no difference, I just get the standard strings instead.

If I use an OR then I can get my "Composition" MessageTemplate to appear but with AND it seems it is ignored.






May 4, 2009 at 4:23 AM
If you configure your validators using the entlib configuration tool, you'll see that the And Composite Validator doesn't expose any properties, only the Or Composite Validator.  I also checked the source code and the AndCompositeValidator indeed doesn't take a messagetemplate parameter in it's constructor.  I'm not sure why it was designed that way though.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
May 4, 2009 at 12:14 PM

I 'll take your work on that. That attribute does show up in Intellisense, which is odd