Hey,
You don't need an Entity-Validator (which is your CustomFooValidator). You
can just use a Pattern validator in the property in the Foo type.
public class Foo
{
[Pattern(....)] //Pattern is for regex
public string SomeProperty {get;set;}
}
And then you still can have this:
[Valid]
public virtual IList<Foo> newNameofthisCollection.
And remember, the custom validator comes in two flavors: Entity and Member
(Property or Field) Validator.
Another solution, remember that you can use Constraint Validator Context,
that is, you can disable the default error in a Entity-Validator and add new
custom messages in the validator.
https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHibernate.Validator/src/NHibernate.Validator.Tests/ConstraintContext/
And with Constraint Validator Context you can point an Error Message to a
member directly, even using Entity-Validator.
Cheers
On Thu, Aug 27, 2009 at 3:23 AM, stromflut <[email protected]> wrote:
>
> Hi there!
>
> I have a collection property of a custom class "foo" (namely an
> IList<foo>) in which class I have a property "value" and another
> property "Regex" which holds the allowed format of "value". To
> validate this property, I added the Attribute [Valid] on the topLevel
> to the collection as following:
> [Valid]
> public virtual IList<foo> newNameofthisCollection
>
> Then I have the CustomFooValidator class which is checking the "value"
> property against the Regex property and returns false if the property
> is invalid. But to make this working, i had to define the Validator to
> be a "ClassValidator" adding "AttributeUsage(AttributeTargets.Class)"
> to the ValidationClass Definition.
>
> If it comes to the validation, MVC adds an InvalidValue Object to the
> ModelState Property of the Object. The Problem is now, MVC does not
> know to what property of "foo", it should map the InvalidValue because
> the Object in the Collection has been validated on ClassLevel.
>
> Does anyone know a way, how to define in the ValidationClass on what
> property it should map the ValidationError? Or is there an other way
> to validate the collection?
>
> Thanks a lot, just even for reading and thinking about my problem!
>
> //stromflut
> >
>
--
Dario Quintana
http://darioquintana.com.ar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---