I did try it like so, it is working, but not as expected. I need to pass
an argument to the resource bundle so it gets correclty displayed with
the name, for example this property:
error.required = Field {0} is required.
When called like this: getText("error.required", {getText("label.name")});
Is displayed (correctly) like so: "Field name is required".
If I use it like this in the annotation:
key = "error.required"
It will be displayed (incorreclty) like so: "Field {0} is required"
because args are not supplied to be used in place of the {0}.
Em 28-04-2010 21:30, mrsv escreveu:
Did you try something like this?
@RequiredStringValidator(
fieldName = "label.name",
key ="error.required ",
message = "Name required.")}
Alex Rodriguez Lopez wrote:
Hi struts users!
I'm on my way to change from XML based validation to annotation
validation.
I've manage to get it working, but (probably due to my little knowledge
of Java annotations) there are some things I can't get to work, so I
apologise if this question is not entirelly Struts related.
I'm trying to get the following XML based validation to annotations at
method level:
<validators>
<field name="user.name">
<field-validator type="requiredstring">
<message>${getText("error.required",
{getText("label.name")})}</message>
</field-validator>
</field>
...
</validators>
So far this works in my action:
@Validations(
requiredStrings = {
@RequiredStringValidator(
fieldName = "user.name",
message = "Name required.")}
)
public String save() {
...
return SUCCESS;
}
But the problem is with this bit<message>${getText("error.required",
{getText("label.name")})}</message> which retrieves a message that has
arguments (also retrieved from a resource bundle).
So how should I use the annotation parameters (key or message) to
retrieve a key with args?
I tried message = getText("error.required", new
String[]{getText("label.name")})
but of course values of annotation params must be constant, and I cannot
define a static value that depends on a getText() lookup.
Is this ever possible to do with annotations?
Any help appreciated!!
Summary: How to use i18n messages with args using annotations for field
validation?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org