struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [struts-site] branch master updated: WW-4940 Adds missing section about customising validation messages
Date Tue, 05 Jun 2018 09:06:08 GMT
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch master
in repository

The following commit(s) were added to refs/heads/master by this push:
     new cf6c8f5  WW-4940 Adds missing section about customising validation messages
cf6c8f5 is described below

commit cf6c8f50937c2b1411d19a3f14107c817497fbf8
Author: Lukasz Lenart <>
AuthorDate: Tue Jun 5 11:05:46 2018 +0200

    WW-4940 Adds missing section about customising validation messages
 source/core-developers/ | 63 ++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/source/core-developers/ b/source/core-developers/
index 2842fc4..d39ff0e 100644
--- a/source/core-developers/
+++ b/source/core-developers/
@@ -234,6 +234,69 @@ See the following example to get an impression:
 <message>${getText("validation.failednotice")} ! ${getText("reason")}: ${getText("validation.inputrequired")}</message>
+### Customizing validation messages
+There is another option to customise validation messages by using parametrized messages.
Either you can use them via
+XML or with annotations.
+#### XML
+To use this new approach you must use a proper header in a `<ActionName>-validation.xml`
file, see below:
+<?xml version="1.0"?>
+<!DOCTYPE validators PUBLIC
+        "-//Apache Struts//XWork Validator 1.0.3//EN"
+        "">
+  ...
+Now you can define validators that will use parametrized messages as below:
+<field name="username">
+    <field-validator type="requiredstring">
+        <message key="errors.required">
+            <param name="0">getText('')</param>
+        </message>
+    </field-validator>
+> NOTE: Please be aware that all the parameters will be evaluated against `ValueStack`,
please do not reference user
+> controlled values or incoming parameters in request as this can lead to a security vulnerability
+Now you can define your properties file with localized messages:
+errors.required={0} is required.
+As you can see you defined a `errors.required` key with a placeholder for the param. The
names of the params are not important,
+order is important as this mechanism uses `MessageFormat` to format the message.
+The final output will be as follow:
+Username is required.
+#### Annotations
+The same mechanism can be used with annotations as follow:
+@RequiredStringValidator(key = "errors.required", messageParams = {
+    "getText('')"
+public void setUsername(String username) {
+    this.username = username;
 ## Validator Flavor
 The validators supplied by the XWork distribution (and any validators you might write yourself)
come in two different 

To stop receiving notification emails like this one, please contact

View raw message