views:

270

answers:

1

Hi,

According to the NHibernate Validator documentation here:

http://nhforge.org/wikis/validator/nhibernate-validator-1-0-0-documentation.aspx

I should be able to pass my resource manager so I can use that for validation error messages. See:

Alternatively you can provide a ResourceManager while checking programmatically the validation rules...

And:

If NHibernate Validator cannot resolve a key from your ResourceManager nor from ValidatorMessage, it falls back to the default built-in values.

It even shows and example of doing just this in an attribute on a entity property:

 // a not null numeric string of 5 characters maximum
    // if the string is longer, the message will
    // be searched in the resource bundle at key 'long'
    [Length(Max = 5, Message = "{long}")]
    [Pattern(Regex = "[0-9]+")]
    [NotNull]
    public string Zip
    {

        get { return zip; }
        set { zip = value; }
    }

However, as far as I can see it doesn't specify how you pass the resource manager to the validation framework - does anyone know how to do this?

Thanks!

+1  A: 

Have a look at this post and answers to this SO question (it describes some gotchas in using message interpolator).

Hope this will help you.

elder_george
Thanks this is useful. However, the NHV documentation suggests that it is easier than having to write your own custom message interpolator : "Alternatively you can provide a ResourceManager while checking programmatically the validation rules...", maybe the docs are misleading?
UpTheCreek
`DefaultMessageInterpolator` has method `Initialize` that accepts culture and couple of ResourceManagers - normal and fall-back. You can cast your `ValidatorEngine.Interpolator` to `DefaultMessageInterpolator` and re-initialize it.
elder_george
Ah, I see - thanks!
UpTheCreek