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

the message is presented as

The field E-mail is mandatory

It works, although is a bit convoluted.



2013/9/25 JOSE L MARTINEZ-AVIAL <jlm...@gmail.com>

> I just created the issue https://issues.apache.org/jira/browse/WW-4208. I
> maybe able to provide a patch for this, if I have time for it.
>
>
> 2013/9/25 JOSE L MARTINEZ-AVIAL <jlm...@gmail.com>
>
>> I will open a ticket. My idea is to add a parameter  to the annotation
>> called keyArgs, which would be a String array. It would be used as follows:
>>
>>
>>         requiredStrings =
>>             {@RequiredStringValidator(type = ValidatorType.SIMPLE,
>>                      keyArgs={"email","one","two"}
>>                     fieldName = "event.email", key =
>> "validation-error.mandatory")},
>>
>> Then the key/message could be something like this:
>>
>> validation-error.mandatory = The field ${getText(keyArgs[0])} is mandatory
>>
>> It would allow to customize the message even further than it allows now.
>> I suppose it would need to be implemented also in xml validations, but I
>> haven't used them, so I don't what would be needed for that.
>>
>>
>>
>>
>> 2013/9/25 Lukasz Lenart <lukaszlen...@apache.org>
>>
>>> 2013/9/25 JOSE L MARTINEZ-AVIAL <jlm...@gmail.com>:
>>> > I have javascript controls for the client-side validation, but we also
>>> want
>>> > to implement server-side validation. I'm not criticizing the
>>> framework, I
>>> > really really like it. I'm just wondering if the validations could be a
>>> > little more flexible to allow reusing message properties.
>>>
>>> I think yes, it is possible - please register an issue and we think
>>> about that, maybe attach some demo or even patch.
>>>
>>>
>>> Regards
>>> --
>>> Ɓukasz
>>> + 48 606 323 122 http://www.lenart.org.pl/
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>>> For additional commands, e-mail: user-h...@struts.apache.org
>>>
>>>
>>
>

Reply via email to