struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JOSE L MARTINEZ-AVIAL <jlm...@gmail.com>
Subject Translation of fieldName in annotated validations
Date Wed, 25 Sep 2013 05:02:37 GMT
Hello,
   I have an Action that receives a parameter *email *on a bean *event*. So
basically the parameter is send to the server with name "*
event.email=jlmagc<at>gmail.com*"'. The bean and the parameter are created
correctly, so this part works ok. Now I want to validate the input using
annotations. In order to do that I'm using the following annotation at the
Action level:

@Validations(
        requiredStrings =
            {@RequiredStringValidator(type = ValidatorType.SIMPLE,
                    fieldName = "event.email", key =
"validation-error.mandatory")}
        )


and in the package.properties I have the following definition
validation-error.mandatory        = The field ${getText(fieldName)} is
mandatory
event.email = e-mail

With this setup, if the parameter event.email is empty or not present, the
validator evaluates the expression and returns to the user the following
message:
"The field e-mail is mandatory".

It evaluates the key as an OGNL expression, retrieves the fieldName,
evaluates the getTest, and elaborate the sentence correctly. So it works ok

The issue here is that this forces me to define a property "event.email"
since the attribute fieldName in the annotation is used both to locate the
field that needs validation, and as argument for the getText. Is it
possible to split that those two roles, so I can user my already existing
property "email", instead of having to duplicate it as "event.email"?

Regards

JL

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message