You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Inge Solvoll <in...@gmail.com> on 2009/05/22 10:38:37 UTC

Re: T5: Customizing validation messages

I've done some digging on this, and found that FieldValidatorSource has got
what I need. I think I have found the logic related to computing message
keys for each validator. I also see that the service methods provides access
to Field, which enables me to include the field label in my message.

As I said in my previous post, what I need is to use this message with
field.getLabel() as the string replacement:

message.required = %s is required

What T5 provides is this:

formName-fieldName-required-message

The problem is that FieldValidatorSourceImpl doesn't have a dedicated method
for computing the validation message, it is done in between other things in
several methods. It seems that I have no other choice but to copy-and-paste
the framework FieldValidatorSourceImpl and make the modifications I need,
which I really don't like since everything else I do with T5 is so nice and
clean :)

Any ideas on a different, smarter and cleaner approach?




On Thu, Apr 16, 2009 at 10:54 AM, Inge Solvoll <in...@gmail.com>wrote:

> Hi!
>
> In our existing app, we always used the following pattern for the standard
> validation messages:
>
> validation.message.required = The field {0} is required. Please enter a
> value and try again.
> validation.message.date = You need to enter a valid date in the {0} field.
>
> You probably get the pattern here. We provide generic messages that only
> needs to know the name/label for the field. The background is that we have
> thousands of messages in our message catalogue, with translations to many
> languages. It just doesn't scale well for us to tailor the validation
> message for every form and form field we create.
>
> One sweet feature for us would be to gain access to the body of the
> <t:label> component to input that string into our generic validation
> messages. I don't like having to do this for every time I specify validation
> on a field. Is it possible to advise a Tapestry service about this? The
> service would do the following:
>
> 1. Get the static message key for a validation type
> 2. Get the field name from the label component, if any.
> 3. Calculate the message based on the key and the field name as a
> parameter.
>
> Thanks for any input!
>
> Inge
>