Validator messages

27 views
Skip to first unread message

Marc Climent

unread,
Mar 2, 2009, 1:09:57 PM3/2/09
to nhusers
Hi,

I've been using NHV and I need to change the "default" messages.

I can't change the ValidatorEngine.Interpolator at runtime (I could
create a DefaultMessageInterpolator and initialize it with a different
bundle and pass it, but I can't and I think I shouldn't) and I can't
configure the resource bundle via XML, or at least I couldn't find how
to do it.

Maybe I'm missing something but it seems that the custom resource
functionality is there but I can't use it right now.

As well, i found this in ClassValidator:
messageBundle = factory.ResourceManager ?? GetDefaultResourceManager
();
defaultMessageBundle = GetDefaultResourceManager();

But digging into the factory, is created internally by the
ValidatorEngine specifying a null ResourceManager.

So the question is... do I have to create my own resource bundles
overriding the original ones or is there a better way to customize the
messages?

Fabio Maulo

unread,
Mar 2, 2009, 1:19:35 PM3/2/09
to nhu...@googlegroups.com
If what you need is only change the message you don't need the interpolator



--
Fabio Maulo

Marc Climent

unread,
Mar 2, 2009, 5:08:23 PM3/2/09
to nhusers
Hi Fabio.

I know in the tag I can specify the message and as well in my custom
validators but I need localization.

I see in the link examples this:
WithMessage("{floor.out.of.range}")

The "{floor.out.of.range}" message is somewhere defined? How can I use
this kind of templates for message localization?

Thanks.

On 2 mar, 19:19, Fabio Maulo <fabioma...@gmail.com> wrote:
> If what you need is only change the message you don't need the
> interpolator <property
> name="Past">
> <past message="your own message"/>
> </property>
>
> If you can use the NHV trunk...http://nhforge.org/blogs/nhibernate/archive/2009/02/18/nhibernate-val...
>
> http://fabiomaulo.blogspot.com/2009/02/diving-in-nhibernatevalidator....
>
> 2009/3/2 Marc Climent <m.clim...@adapting.com>

Fabio Maulo

unread,
Mar 2, 2009, 5:19:10 PM3/2/09
to nhu...@googlegroups.com
For base validators all resources are deployed with NHV.
If you want, you can change the resource using a resource-editor (from microsoft of some other free).

2009/3/2 Marc Climent <m.cl...@adapting.com>



--
Fabio Maulo

Marc Climent

unread,
Mar 2, 2009, 5:49:05 PM3/2/09
to nhusers
Yes, I can do that.

Anyway, will this feature be available in the future? Can I do
something about it?

I can see in the original Hibernate Validator documentation that the
messages can be overriden with a properties file and with an
Interpolator:
http://www.hibernate.org/hib_docs/validator/reference/en/html/validator-defineconstraints.html#validator-defineconstraints-error

As well, I can do it with an Interpolator. I tested this and it works,
but to me it seems like rewriting the default interpolator because I
cannot pass a different Resouce bundle.

On 2 mar, 23:19, Fabio Maulo <fabioma...@gmail.com> wrote:
> For base validators all resources are deployed with NHV.If you want, you can
> change the resource using a resource-editor (from microsoft of some other
> free).
>
> 2009/3/2 Marc Climent <m.clim...@adapting.com>

Dario Quintana

unread,
Mar 2, 2009, 5:56:43 PM3/2/09
to nhu...@googlegroups.com
Which feature ?

{floor.out.of.range} is the name of a resource string, you can use it.


On Mon, Mar 2, 2009 at 8:49 PM, Marc Climent <m.cl...@adapting.com> wrote:

Anyway, will this feature be available in the future? Can I do
something about it?



--
Dario Quintana
http://darioquintana.com.ar

Marc Climent

unread,
Mar 3, 2009, 4:46:23 AM3/3/09
to nhusers
Sorry, I meant the possibility of specifying a custom Resource bundle
to override some default messages with localization.

Finally I am creating my own Interpolator that works like the
DefaultInterpolator but tries to get the messages from the local
resources for some default validators and for my own ones. Then if not
found returns the message from the defaultInterpolator. This is the
most flexible solution I've found.

Thanks for the responses.

On 2 mar, 23:56, Dario Quintana <conta...@darioquintana.com.ar> wrote:
> Which feature ?
>
> {floor.out.of.range} is the name of a resource string, you can use it.
>

s_tristan

unread,
Mar 3, 2009, 12:09:25 PM3/3/09
to nhusers
Can you share this Interpolator?
> > Dario Quintanahttp://darioquintana.com.ar- Скрыть цитируемый текст -
>
> - Показать цитируемый текст -

Dario Quintana

unread,
Mar 3, 2009, 6:27:21 PM3/3/09
to nhu...@googlegroups.com
Next week (after exams) I'll have a look to the interpolator and review this topic.

Marc Climent

unread,
Mar 4, 2009, 10:58:37 AM3/4/09
to nhusers
I posted an entry on my blog about the subject, I hope this helps:
http://codelog.climens.net/2009/03/04/nhibernate-validator-custom-messages/

If someone thinks that it's interesting to put this on the wiki, I
have no objections and I can do it myself.
> > > Dario Quintanahttp://darioquintana.com.ar-Скрыть цитируемый текст -

Fabio Maulo

unread,
Mar 4, 2009, 11:09:54 AM3/4/09
to nhu...@googlegroups.com
2009/3/4 Marc Climent <m.cl...@adapting.com>

If someone thinks that it's interesting to put this on the wiki, I
have no objections and I can do it myself.

Please.

--
Fabio Maulo

Marc Climent

unread,
Mar 4, 2009, 12:32:25 PM3/4/09
to nhusers

Fabio Maulo

unread,
Mar 4, 2009, 1:38:42 PM3/4/09
to nhu...@googlegroups.com
2009/3/4 Marc Climent <m.cl...@adapting.com>

Done.

http://nhforge.org/wikis/howtonh/create-a-custom-message-interpolator-for-nhibernate-validator.aspx

Friends, this is the right spirit! if you care about NH's projects future.

The NH team can use his "free time" to work in NH projects (mean NH + Contrib) and the community share his experience and help with all other very important stuff (as HowTo, documentation, reference and so on).

Thanks Marc.

Fabio Maulo
Reply all
Reply to author
Forward
0 new messages