You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by JOSE L MARTINEZ-AVIAL <jl...@gmail.com> on 2013/12/20 16:57:47 UTC

Re: Translation of fieldName in annotated validations

Hi,
  Just reviewing old things,  I discovered I didn't answer you. The think
is that the same effect can be obtained using the already existing
functionality. I can create the following annotation to validate a field:

@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName =
"phoneCountryCode",
                    messageParams={"getText('PhoneCountryCode.label')"},key
= "validation-error.mandatory")},

And then define the following i18n properties
PhoneCountryCode.label       = Country Code
validation-error.mandatory     = The field {0} is mandatory

And then the generated message will be "The field Country Code is
mandatory". So I'm going to close this issue, as it is no longer a problem.

Best regards and thanks
JL




2013/9/30 Lukasz Lenart <lu...@apache.org>

> 2013/9/25 JOSE L MARTINEZ-AVIAL <jl...@gmail.com>:
> > Well, I have found a workaround that is not much of a hacking. The
> > annotations has a messageParameters that is evaluated against the
> > valuestack. Since the action is in the valuestack, and it implements
> > ActionSupport,I can pass a parameter that is a call to getText.
> >
> >         requiredStrings =
> >             {@RequiredStringValidator(type = ValidatorType.SIMPLE,
> >                     messageParams={"getText('email')"},
> >                     fieldName = "event.email", key =
> > "validation-error.mandatory")},
> >
> > and by defining the message as:
> >
> > validation-error.mandatory        = The field {0} is mandatory
> > email = E-mail
>
> I'm not sure if I get you right - does it meet your requirements or do
> you expect something different?
>
>
> Regards
> --
> Ɓukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>