Modified: websites/production/struts/content/docs/validation.html
==============================================================================
--- websites/production/struts/content/docs/validation.html (original)
+++ websites/production/struts/content/docs/validation.html Tue Aug 25 07:18:20
2015
@@ -139,15 +139,18 @@ under the License.
<div class="pagecontent">
<div class="wiki-content">
<div id="ConfluenceContent"><p>Struts 2 validation is configured
via XML or annotations. Manual validation in the action is also possible, and
may be combined with XML and annotation-driven validation.</p><p>Validation
also depends on both the <code>validation</code> and <code>workflow</code>
interceptors (both are included in the default interceptor stack). The
<code>validation</code> interceptor does the validation itself and creates a
list of field-specific errors. The <code>workflow</code> interceptor checks for
the presence of validation errors: if any are found, it returns the "input"
result (by default), taking the user back to the form which contained the
validation errors.</p><p>If we're using the default settings <em>and</em> our
action doesn't have an "input" result defined <em>and</em> there are validation
(or, incidentally, type conversion) errors, we'll get an error message back
telling us there's no "input" result defined for the action.</p><p><strong>CONT
ENTS</strong></p><p><style type="text/css">/*<![CDATA[*/
-div.rbtoc1438274126726 {padding: 0px;}
-div.rbtoc1438274126726 ul {list-style: none;margin-left: 0px;}
-div.rbtoc1438274126726 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1440486361978 {padding: 0px;}
+div.rbtoc1440486361978 ul {list-style: none;margin-left: 0px;}
+div.rbtoc1440486361978 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1438274126726">
+/*]]>*/</style></p><div class="toc-macro rbtoc1440486361978">
<ul class="toc-indentation"><li><span class="TOCOutline">1</span> <a
shape="rect" href="#Validation-UsingAnnotations">Using
Annotations</a></li><li><span class="TOCOutline">2</span> <a shape="rect"
href="#Validation-BeanValidation">Bean Validation</a></li><li><span
class="TOCOutline">3</span> <a shape="rect"
href="#Validation-Examples">Examples</a></li><li><span
class="TOCOutline">4</span> <a shape="rect"
href="#Validation-BundledValidators">Bundled Validators</a></li><li><span
class="TOCOutline">5</span> <a shape="rect"
href="#Validation-RegisteringValidators">Registering
Validators</a></li><li><span class="TOCOutline">6</span> <a shape="rect"
href="#Validation-TurningonValidation">Turning on Validation</a></li><li><span
class="TOCOutline">7</span> <a shape="rect"
href="#Validation-ValidatorScopes">Validator Scopes</a>
<ul class="toc-indentation"><li><span class="TOCOutline">7.1</span> <a
shape="rect" href="#Validation-Notes">Notes</a></li></ul>
</li><li><span class="TOCOutline">8</span> <a shape="rect"
href="#Validation-DefiningValidationRules">Defining Validation
Rules</a></li><li><span class="TOCOutline">9</span> <a shape="rect"
href="#Validation-LocalizingandParameterizingMessages">Localizing and
Parameterizing Messages</a></li><li><span class="TOCOutline">10</span> <a
shape="rect" href="#Validation-ValidatorFlavor">Validator
Flavor</a></li><li><span class="TOCOutline">11</span> <a shape="rect"
href="#Validation-Non-FieldValidatorVsField-Validatorvalidatortypes">Non-Field
Validator Vs Field-Validator</a></li><li><span class="TOCOutline">12</span> <a
shape="rect" href="#Validation-Short-CircuitingValidator">Short-Circuiting
Validator</a></li><li><span class="TOCOutline">13</span> <a shape="rect"
href="#Validation-HowValidatorsofanActionareFound">How Validators of an Action
are Found</a></li><li><span class="TOCOutline">14</span> <a shape="rect"
href="#Validation-Writingcustomvalidators">Writing custom validators</a></li>
<li><span class="TOCOutline">15</span> <a shape="rect"
href="#Validation-Resources">Resources</a></li><li><span
class="TOCOutline">16</span> <a shape="rect" href="#Validation-Next:">Next:
Localization</a></li></ul>
-</div><h2 id="Validation-UsingAnnotations">Using Annotations</h2><p><a
shape="rect" href="validation-annotation.html">Annotations</a> can be used as
an alternative to XML for validation.</p><p> </p><h2
id="Validation-BeanValidation">Bean Validation</h2><p>With struts 2.5 comes the
Bean Validation Plugin. That is an alternative to the classic struts validation
described here. See the <a shape="rect"
href="bean-validation-plugin.html">Plugin Page</a> for details.</p><h2
id="Validation-Examples">Examples</h2><p>In all examples given here, the
validation message displayed is given in plain English - to internationalize
the message, put the string in a properties file and use a property key
instead, specified by the 'key' attribute. It will be looked up by the
framework (see <a shape="rect"
href="localization.html">Localization</a>).</p><ol><li><a shape="rect"
href="basic-validation.html">Basic Validation</a></li><li><a shape="rect"
href="client-validation.html">Client-side Validati
on</a></li><li><a shape="rect" href="ajax-validation.html">AJAX
Validation</a></li><li><a shape="rect" href="using-field-validators.html">Using
Field Validators</a></li><li><a shape="rect"
href="using-non-field-validators.html">Using Non Field
Validators</a></li><li><a shape="rect"
href="using-visitor-field-validator.html">Using Visitor Field
Validator</a></li><li><a shape="rect"
href="how-do-we-repopulate-controls-when-validation-fails.html">How do we
repopulate controls when validation fails</a> (FAQ entry)</li></ol><h2
id="Validation-BundledValidators">Bundled Validators</h2><div
class="confluence-information-macro confluence-information-macro-note"><p
class="title">Note</p><span class="aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>When using a Field Validator,
Field Validator Syntax is <strong>ALWAYS</strong> preferable than using the
Plain Validator Syntax as it facilitates grouping of fi
eld-validators according to fields. This is very handy especially if a field
needs to have many <code>field-validators</code> which is almost always the
case.</p></div></div><ol><li><a shape="rect"
href="conversion-validator.html">conversion validator</a></li><li><a
shape="rect" href="date-validator.html">date validator</a></li><li><a
shape="rect" href="double-validator.html">double validator</a></li><li><a
shape="rect" href="email-validator.html">email validator</a></li><li><a
shape="rect" href="expression-validator.html">expression
validator</a></li><li><a shape="rect"
href="fieldexpression-validator.html">fieldexpression validator</a></li><li><a
shape="rect" href="int-validator.html">int validator</a></li><li><a
shape="rect" href="regex-validator.html">regex validator</a></li><li><a
shape="rect" href="required-validator.html">required validator</a></li><li><a
shape="rect" href="requiredstring-validator.html">requiredstring
validator</a></li><li><a shape="rect" href="short-validat
or.html">short validator</a></li><li><a shape="rect"
href="stringlength-validator.html">stringlength validator</a></li><li><a
shape="rect" href="url-validator.html">url validator</a></li><li><a
shape="rect" href="visitor-validator.html">visitor validator</a></li><li><a
shape="rect" href="conditionalvisitor-validator.html">conditionalvisitor
validator</a></li></ol><h2 id="Validation-RegisteringValidators">Registering
Validators</h2><div class="error"><span class="error">Error formatting macro:
snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span>
</div><p>The following list shows the default validators included in the
framework and is an example of the syntax used to declare our own
validators.</p><div class="error"><span class="error">Error formatting macro:
snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span>
</div><div class="confluence-information-macro
confluence-information-macro-note"><p class="title">Struts 2.1 and
Prior</p><span class="
aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>The <code>validators.xml</code>
used to reference a DTD hosted by Opensymphony, the original location of the
XWork project. Since the the move to Apache Struts, DTDs were changed. Please
ensure in your projects to include the DTD header as described in the examples
found here</p></div></div><div class="confluence-information-macro
confluence-information-macro-note"><p class="title">Struts 2.0.7 and
Prior</p><span class="aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>The <code>validators.xml</code>
containing custom validators needs to contain a copy of the default validators.
No DTD was used in validators.xml. See: <a shape="rect" class="external-link"
href="http://struts.apache.org/2.x/docs/release-notes-208.html#ReleaseNotes2.0.8-MigrationfrompreviousRelease
s">http://struts.apache.org/2.x/docs/release-notes-208.html#ReleaseNotes2.0.8-MigrationfrompreviousReleases</a></p></div></div><h2
id="Validation-TurningonValidation">Turning on Validation</h2><p>The default
interceptor stack, "defaultStack", already has validation turned on. When
creating your own interceptor-stack be sure to include <strong>both</strong>
the <code>validation</code> and <code>workflow</code> interceptors. From
<code>struts-default.xml</code>:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div><h2 id="Validation-UsingAnnotations">Using Annotations</h2><p><a
shape="rect" href="validation-annotation.html">Annotations</a> can be used as
an alternative to XML for validation.</p><p> </p><h2
id="Validation-BeanValidation">Bean Validation</h2><p>With struts 2.5 comes the
Bean Validation Plugin. That is an alternative to the classic struts validation
described here. See the <a shape="rect"
href="bean-validation-plugin.html">Plugin Page</a> for details.</p><h2
id="Validation-Examples">Examples</h2><p>In all examples given here, the
validation message displayed is given in plain English - to internationalize
the message, put the string in a properties file and use a property key
instead, specified by the 'key' attribute. It will be looked up by the
framework (see <a shape="rect"
href="localization.html">Localization</a>).</p><ol><li><a shape="rect"
href="basic-validation.html">Basic Validation</a></li><li><a shape="rect"
href="client-validation.html">Client-side Validati
on</a></li><li><a shape="rect" href="ajax-validation.html">AJAX
Validation</a></li><li><a shape="rect" href="using-field-validators.html">Using
Field Validators</a></li><li><a shape="rect"
href="using-non-field-validators.html">Using Non Field
Validators</a></li><li><a shape="rect"
href="using-visitor-field-validator.html">Using Visitor Field
Validator</a></li><li><a shape="rect"
href="how-do-we-repopulate-controls-when-validation-fails.html">How do we
repopulate controls when validation fails</a> (FAQ entry)</li></ol><h2
id="Validation-BundledValidators">Bundled Validators</h2><div
class="confluence-information-macro confluence-information-macro-note"><p
class="title">Note</p><span class="aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>When using a Field Validator,
Field Validator Syntax is <strong>ALWAYS</strong> preferable than using the
Plain Validator Syntax as it facilitates grouping of fi
eld-validators according to fields. This is very handy especially if a field
needs to have many <code>field-validators</code> which is almost always the
case.</p></div></div><ol><li><a shape="rect"
href="conversion-validator.html">conversion validator</a></li><li><a
shape="rect" href="date-validator.html">date validator</a></li><li><a
shape="rect" href="double-validator.html">double validator</a></li><li><a
shape="rect" href="email-validator.html">email validator</a></li><li><a
shape="rect" href="expression-validator.html">expression
validator</a></li><li><a shape="rect"
href="fieldexpression-validator.html">fieldexpression validator</a></li><li><a
shape="rect" href="int-validator.html">int validator</a></li><li><a
shape="rect" href="regex-validator.html">regex validator</a></li><li><a
shape="rect" href="required-validator.html">required validator</a></li><li><a
shape="rect" href="requiredstring-validator.html">requiredstring
validator</a></li><li><a shape="rect" href="short-validat
or.html">short validator</a></li><li><a shape="rect"
href="stringlength-validator.html">stringlength validator</a></li><li><a
shape="rect" href="url-validator.html">url validator</a></li><li><a
shape="rect" href="visitor-validator.html">visitor validator</a></li><li><a
shape="rect" href="conditionalvisitor-validator.html">conditionalvisitor
validator</a></li></ol><h2 id="Validation-RegisteringValidators">Registering
Validators</h2><p>Validation rules are handled by validators, which must be
registered with
+the ValidatorFactory (using the registerValidator method). The simplest way to
do so is to add a file name
+validators.xml in the root of the classpath (/WEB-INF/classes) that declares
+all the validators you intend to use.</p><p>The following list shows the
default validators included in the framework and is an example of the syntax
used to declare our own validators.</p><div class="error"><span
class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><div
class="confluence-information-macro confluence-information-macro-note"><p
class="title">Struts 2.1 and Prior</p><span class="aui-icon aui-icon-small
aui-iconfont-warning confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>The <code>validators.xml</code>
used to reference a DTD hosted by Opensymphony, the original location of the
XWork project. Since the the move to Apache Struts, DTDs were changed. Please
ensure in your projects to include the DTD header as described in the examples
found here</p></div></div><div class="confluence-information-macro
confluence-information-macro-note"><p class="title">Struts 2.0.7 a
nd Prior</p><span class="aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>The <code>validators.xml</code>
containing custom validators needs to contain a copy of the default validators.
No DTD was used in validators.xml. See: <a shape="rect" class="external-link"
href="http://struts.apache.org/2.x/docs/release-notes-208.html#ReleaseNotes2.0.8-MigrationfrompreviousReleases">http://struts.apache.org/2.x/docs/release-notes-208.html#ReleaseNotes2.0.8-MigrationfrompreviousReleases</a></p></div></div><h2
id="Validation-TurningonValidation">Turning on Validation</h2><p>The default
interceptor stack, "defaultStack", already has validation turned on. When
creating your own interceptor-stack be sure to include <strong>both</strong>
the <code>validation</code> and <code>workflow</code> interceptors. From
<code>struts-default.xml</code>:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="c
odeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><interceptor-stack name="defaultStack">
...
<interceptor-ref name="validation">
@@ -161,7 +164,137 @@ div.rbtoc1438274126726 li {margin-left:
</div></div><p>Beginning with version 2.0.4 Struts provides an extension to
XWork's <code>com.opensymphony.xwork2.validator.ValidationInterceptor</code>
interceptor.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><interceptor name="validation"
class="org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor"/>
</pre>
-</div></div><p>This interceptor allows us to turn off validation for a
specific method by using the
<code>@org.apache.struts2.interceptor.validation.SkipValidation</code>
annotation on the action method.</p><h2
id="Validation-ValidatorScopes">Validator Scopes</h2><div class="error"><span
class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><div
class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><h3
id="Validation-Notes">Notes</h3><div class="error"><span class="error">Error
formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20,
Size: 20</span> </div><h2 id="Validation-DefiningValidationRules">Defining
Validation Rules</h2><div class="error"><span class="error">Error formatting
macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span>
</div><div class="error"><span class="error">Error formatting
macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size:
20</span> </div><div class="error"><span class="error">Error formatting macro:
snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span>
</div><div class="confluence-information-macro
confluence-information-macro-note"><span class="aui-icon aui-icon-small
aui-iconfont-warning confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>In this context, "Action Alias"
refers to the action name as given in the Struts configuration. Often, the name
attribute matches the method name, but they may also differ.</p></div></div><h2
id="Validation-LocalizingandParameterizingMessages">Localizing and
Parameterizing Messages</h2><div class="error"><span class="error">Error
formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20,
Size: 20</span> </div><div class="error"><span class="error">Error formatting
macro: snippet: java.lang.IndexOutOfBoundsException: Inde
x: 20, Size: 20</span> </div><div class="error"><span class="error">Error
formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20,
Size: 20</span> </div><div class="error"><span class="error">Error formatting
macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span>
</div><h2 id="Validation-ValidatorFlavor">Validator Flavor</h2><div
class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><h2
id="Validation-Non-FieldValidatorVsField-Validatorvalidatortypes">Non-Field
Validator Vs Field-Validator <span class="confluence-anchor-link"
id="Validation-validatortypes"></span></h2><p>There are two ways you can define
validators in your -validation.xml
file:</p><ol><li><validator></li><li><field-validator></li></ol><p>Keep
the following in mind when using either syntax:</p><p>Non-Field-Validator: The
<validator> element allows you to declare both types of
validators (either a plain Validator a field-specific
FieldValidator).</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</div></div><p>This interceptor allows us to turn off validation for a
specific method by using the
<code>@org.apache.struts2.interceptor.validation.SkipValidation</code>
annotation on the action method.</p><h2
id="Validation-ValidatorScopes">Validator Scopes</h2><p>Field validators, as
the name indicate, act on single fields accessible through an action.
+A validator, in contrast, is more generic and can do validations in the full
action context,
+involving more than one field (or even no field at all) in validation rule.
+Most validations can be defined on per field basis. This should be preferred
over
+non-field validation wherever possible, as field validator messages are bound
to the
+related field and will be presented next to the corresponding input element in
the
+respecting view.</p><p>Non-field validators only add action level messages.
Non-field validators
+are mostly domain specific and therefore offer custom implementations.
+The most important standard non-field validator provided by XWork
+is ExpressionValidator.</p><h3 id="Validation-Notes">Notes</h3><p>Non-field
validators takes precedence over field validators
+regardless of the order they are defined in *-validation.xml. If a non-field
+validator is short-circuited, it will causes its non-field validator to not
+being executed. See validation framework documentation for more info.</p><h2
id="Validation-DefiningValidationRules">Defining Validation
Rules</h2><p></p><p>Validation rules can be specified:</p>
+<ol><li> Per Action class: in a file named ActionName-validation.xml</li><li>
Per Action alias: in a file named ActionName-alias-validation.xml</li><li>
Inheritance hierarchy and interfaces implemented by Action class:
+ XWork searches up the inheritance tree of the action to find default
+ validations for parent classes of the Action and interfaces
implemented</li></ol>
+<p>Here is an example for SimpleAction-validation.xml:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator
1.0.3//EN"
+
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
+<validators>
+ <field name="bar">
+ <field-validator type="required">
+ <message>You must enter a value for bar.</message>
+ </field-validator>
+ <field-validator type="int">
+ <param name="min">6</param>
+ <param name="max">10</param>
+ <message>bar must be between ${min} and ${max}, current value
is ${bar}.</message>
+ </field-validator>
+ </field>
+ <field name="bar2">
+ <field-validator type="regex">
+ <param name="expression">[0-9],[0-9]</param>
+ <message>The value of bar2 must be in the format "x,
y", where x and y are between 0 and 9</message>
+ </field-validator>
+ </field>
+ <field name="date">
+ <field-validator type="date">
+ <param name="min">12/22/2002</param>
+ <param name="max">12/25/2002</param>
+ <message>The date must be between 12-22-2002 and
12-25-2002.</message>
+ </field-validator>
+ </field>
+ <field name="foo">
+ <field-validator type="int">
+ <param name="min">0</param>
+ <param name="max">100</param>
+ <message key="foo.range">Could not find
foo.range!</message>
+ </field-validator>
+ </field>
+ <validator type="expression">
+ <param name="expression">foo lt bar </param>
+ <message>Foo must be greater than Bar. Foo = ${foo}, Bar =
${bar}.</message>
+ </validator>
+</validators>
+]]></script>
+</div></div><p>Here we can see the configuration of validators for the
SimpleAction class.
+Validators (and field-validators) must have a type attribute, which refers
+to a name of an Validator registered with the ValidatorFactory as above.
+Validator elements may also have <param> elements with name and value
attributes
+to set arbitrary parameters into the Validator instance. See below for
discussion
+of the message element.</p><div class="confluence-information-macro
confluence-information-macro-note"><span class="aui-icon aui-icon-small
aui-iconfont-warning confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>In this context, "Action Alias"
refers to the action name as given in the Struts configuration. Often, the name
attribute matches the method name, but they may also differ.</p></div></div><h2
id="Validation-LocalizingandParameterizingMessages">Localizing and
Parameterizing Messages</h2><p></p><p>Each Validator or Field-Validator element
must define one message element inside
+the validator element body. The message element has 1 attributes, key which is
not
+required. The body of the message tag is taken as the default message which
should
+be added to the Action if the validator fails. Key gives a message key to look
up
+in the Action's ResourceBundles using getText() from LocaleAware if the Action
+implements that interface (as ActionSupport does). This provides for Localized
+messages based on the Locale of the user making the request (or whatever Locale
+you've set into the LocaleAware Action). After either retrieving the message
from
+the ResourceBundle using the Key value, or using the Default message, the
current
+Validator is pushed onto the ValueStack, then the message is parsed for \${...}
+sections which are replaced with the evaluated value of the string between the
+\${ and }. This allows you to parameterize your messages with values from the
+Validator, the Action, or both.</p>
+
+
+<p></p><p>If the validator fails, the validator is pushed onto the ValueStack
and the
+message - either the default or the locale-specific one if the key attribute is
+defined (and such a message exists) - is parsed for ${...} sections which are
+replaced with the evaluated value of the string between the ${ and }. This
+allows you to parameterize your messages with values from the validator, the
+Action, or both. </p>
+
+<p></p><p><b>NOTE:</b> Since validation rules are in an XML file, you must
make sure
+you escape special characters. For example, notice that in the expression
+validator rule above we use "&gt;" instead of ">". Consult a resource
on XML
+for the full list of characters that must be escaped. The most commonly used
+characters that must be escaped are: & (use &amp<img align="middle"
class="emoticon" src="null/icons/emoticons/wink.png" height="16" width="16"
alt="" border="0">, > (user &gt<img align="middle" class="emoticon"
src="null/icons/emoticons/wink.png" height="16" width="16" alt="" border="0">,
and < (use &lt<img align="middle" class="emoticon"
src="null/icons/emoticons/wink.png" height="16" width="16" alt=""
border="0">.</p>
+
+<p></p><p>Here is an example of a parameterized message:</p>
+<p>This will pull the min and max parameters from the IntRangeFieldValidator
and
+the value of bar from the Action.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+bar must be between ${min} and ${max}, current value is ${bar}.
+]]></script>
+</div></div><p></p><p>Another notable fact is that the provided message value
is capable of containing OGNL expressions.
+Keeping this in mind, it is possible to construct quite sophisticated
messages.</p>
+<p>See the following example to get an impression:</p>
+<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+<message>${getText("validation.failednotice")}!
${getText("reason")}:
${getText("validation.inputrequired")}</message>
+]]></script>
+</div></div><h2 id="Validation-ValidatorFlavor">Validator
Flavor</h2><p></p><p>The validators supplied by the XWork distribution (and any
validators you
+might write yourself) come in two different flavors:</p>
+
+<p></p><ol><li> Plain Validators / Non-Field validators </li><li>
FieldValidators </li></ol>
+
+<p></p><p>Plain Validators (such as the ExpressionValidator) perform
validation checks
+that are not inherently tied to a single specified field. When you declare a
+plain Validator in your -validation.xml file you do not associate a fieldname
+attribute with it. (You should avoid using plain Validators within the
+<field-validator> syntax described below.)</p>
+
+<p></p><p>FieldValidators (such as the EmailValidator) are designed to perform
+validation checks on a single field. They require that you specify a fieldname
+attribute in your -validation.xml file. There are two different (but
equivalent)
+XML syntaxes you can use to declare FieldValidators (see "<validator> vs.
+<field-Validator> syntax" below).</p>
+
+<p></p><p>There are two places where the differences between the two validator
flavors
+are important to keep in mind:</p>
+
+<p></p><ol><li> when choosing the xml syntax used for declaring a validator
+(either <validator> or <field-validator>)</li><li> when using the
short-circuit capability</li></ol>
+
+<p></p><p><b>NOTE:</b>Note that you do not declare what "flavor" of validator
you are
+using in your -validation.xml file, you just declare the name of the validator
+to use and Struts will know whether it's a "plain Validator" or a
"FieldValidator"
+by looking at the validation class that the validator's programmer chose
+to implement.</p><h2
id="Validation-Non-FieldValidatorVsField-Validatorvalidatortypes">Non-Field
Validator Vs Field-Validator <span class="confluence-anchor-link"
id="Validation-validatortypes"></span></h2><p>There are two ways you can define
validators in your -validation.xml
file:</p><ol><li><validator></li><li><field-validator></li></ol><p>Keep
the following in mind when using either syntax:</p><p>Non-Field-Validator: The
<validator> element allows you to declare both types of validators
(either a plain Validator a field-specific FieldValidator).</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><validator type="expression>
<param name="expression">foo gt bar</param>
<message>foo must be great than bar.</message>
@@ -202,7 +335,114 @@ div.rbtoc1438274126726 li {margin-left:
<message>The email address you entered is not valid.</message>
</validator>
</pre>
-</div></div><h2 id="Validation-Short-CircuitingValidator">Short-Circuiting
Validator</h2><div class="error"><span class="error">Error formatting macro:
snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span>
</div><div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><div
class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><div
class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><div
class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><div
class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><h2
id="Validation-HowValidatorsofanActionareFound">How
Validators of an Action are Found</h2><div class="error"><span
class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div><h2
id="Validation-Writingcustomvalidators">Writing custom validators</h2><p>If you
want to write custom validator use on of these classes as a starting
point:</p><ul style="list-style-type:
square;"><li>com.opensymphony.xwork2.validator.validators.ValidatorSupport</li><li>com.opensymphony.xwork2.validator.validators.FieldValidatorSupport</li><li>com.opensymphony.xwork2.validator.validators.RangeValidatorSupport</li><li>com.opensymphony.xwork2.validator.validators.RepopulateConversionErrorFieldValidatorSupport</li></ul><h2
id="Validation-Resources">Resources</h2><p><a shape="rect"
class="external-link"
href="http://today.java.net/pub/a/today/2006/01/19/webwork-validation.html"
rel="nofollow">WebWork Validation</a></p><h2 id="Validation-Next:">Next: <a
shape="rect" href="localization.html">Localization</a><
/h2></div>
+</div></div><h2 id="Validation-Short-CircuitingValidator">Short-Circuiting
Validator</h2><p></p><p>It is possible to short-circuit a stack of validators.
+Here is another sample config file containing validation rules from the
+Xwork test cases: Notice that some of the <field-validator> and
+<validator> elements have the short-circuit attribute set to
true.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+<!DOCTYPE validators PUBLIC
+ "-//Apache Struts//XWork Validator 1.0.3//EN"
+
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
+<validators>
+ <!-- Field Validators for email field -->
+ <field name="email">
+ <field-validator type="required"
short-circuit="true">
+ <message>You must enter a value for email.</message>
+ </field-validator>
+ <field-validator type="email"
short-circuit="true">
+ <message>Not a valid e-mail.</message>
+ </field-validator>
+ </field>
+ <!-- Field Validators for email2 field -->
+ <field name="email2">
+ <field-validator type="required">
+ <message>You must enter a value for email2.</message>
+ </field-validator>
+ <field-validator type="email">
+ <message>Not a valid e-mail2.</message>
+ </field-validator>
+ </field>
+ <!-- Plain Validator 1 -->
+ <validator type="expression">
+ <param
name="expression">email.equals(email2)</param>
+ <message>Email not the same as email2</message>
+ </validator>
+ <!-- Plain Validator 2 -->
+ <validator type="expression" short-circuit="true">
+ <param
name="expression">email.startsWith('mark')</param>
+ <message>Email does not start with mark</message>
+ </validator>
+</validators>
+]]></script>
+</div></div><p></p><p><b>short-circuiting and Validator flavors</b></p>
+<p>Plain validator takes precedence over field-validator. They get validated
+first in the order they are defined and then the field-validator in the order
+they are defined. Failure of a particular validator marked as short-circuit
+will prevent the evaluation of subsequent validators and an error (action
+error or field error depending on the type of validator) will be added to
+the ValidationContext of the object being validated.</p>
+
+<p></p><p>In the example above, the actual execution of validator would be as
follows:</p>
+
+<p></p><ol><li> Plain Validator 1</li><li> Plain Validator 2</li><li> Field
Validators for email field</li><li> Field Validators for email2 field</li></ol>
+
+<p></p><p>Since Plain Validator 2 is short-circuited, if its validation failed,
+it will causes Field validators for email field and Field validators for email2
+field to not be validated as well.</p>
+
+<p></p><p><b>Usefull Information:</b>
+More complicated validation should probably be done in the validate()
+method on the action itself (assuming the action implements Validatable
+interface which ActionSupport already does).</p>
+
+<p></p><p>
+A plain Validator (non FieldValidator) that gets short-circuited will
+completely break out of the validation stack. No other validators will be
+evaluated and plain validators takes precedence over field validators meaning
+that they get evaluated in the order they are defined before field validators
+get a chance to be evaluated.
+</p><p></p><p><b>Short cuircuiting and validator flavours</b></p>
+<p>A FieldValidator that gets short-circuited will only prevent other
+FieldValidators for the same field from being evaluated. Note that this
+"same field" behavior applies regardless of whether the <validator> or
+<field-validator> syntax was used to declare the validation rule.
+By way of example, given this -validation.xml file:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+<validator type="required" short-circuit="true">
+ <param name="fieldName">bar</param>
+ <message>You must enter a value for bar.</message>
+</validator>
+
+<validator type="expression">
+ <param name="expression">foo gt bar</param>
+ <message>foo must be great than bar.</message>
+</validator>
+]]></script>
+</div></div><p></p><p>both validators will be run, even if the "required"
validator short-circuits.
+"required" validators are FieldValidator's and will not short-circuit the plain
+ExpressionValidator because FieldValidators only short-circuit other checks on
+that same field. Since the plain Validator is not field specific, it is
+not short-circuited.</p><h2
id="Validation-HowValidatorsofanActionareFound">How Validators of an Action are
Found</h2><p></p><p>As mentioned above, the framework will also search up the
inheritance tree
+of the action to find default validations for interfaces and parent classes of
+the Action. If you are using the short-circuit attribute and relying on
+default validators higher up in the inheritance tree, make sure you don't
+accidentally short-circuit things higher in the tree that you really want!</p>
+<p>
+The effect of having common validators on both
+</p>
+<ul><li><actionClass>-validation.xml</li><li><actionClass>-<actionAlias>-validation.xml</li></ul>
+<p>
+It should be noted that the nett effect will be validation on both the
validators available
+in both validation configuration file. For example if we have 'requiredstring'
validators defined
+in both validation xml file for field named 'address', we will see 2
validation error indicating that
+the the address cannot be empty (assuming validation failed). This is due to
WebWork
+will merge validators found in both validation configuration files.
+</p>
+<p>
+The logic behind this design decision is such that we could have common
validators in
+<actionClass>-validation.xml and more context specific validators to be
located
+in <actionClass>-<actionAlias>-validation.xml
+</p><h2 id="Validation-Writingcustomvalidators">Writing custom
validators</h2><p>If you want to write custom validator use on of these classes
as a starting point:</p><ul style="list-style-type:
square;"><li>com.opensymphony.xwork2.validator.validators.ValidatorSupport</li><li>com.opensymphony.xwork2.validator.validators.FieldValidatorSupport</li><li>com.opensymphony.xwork2.validator.validators.RangeValidatorSupport</li><li>com.opensymphony.xwork2.validator.validators.RepopulateConversionErrorFieldValidatorSupport</li></ul><h2
id="Validation-Resources">Resources</h2><p><a shape="rect"
class="external-link"
href="http://today.java.net/pub/a/today/2006/01/19/webwork-validation.html"
rel="nofollow">WebWork Validation</a></p><h2 id="Validation-Next:">Next: <a
shape="rect" href="localization.html">Localization</a></h2></div>
</div>
<div class="tabletitle">
Modified:
websites/production/struts/content/docs/validationparameter-annotation.html
==============================================================================
--- websites/production/struts/content/docs/validationparameter-annotation.html
(original)
+++ websites/production/struts/content/docs/validationparameter-annotation.html
Tue Aug 25 07:18:20 2015
@@ -141,19 +141,27 @@ under the License.
<div id="ConfluenceContent">
<h1
id="ValidationParameterannotation-ValidationParameterAnnotation">ValidationParameter
Annotation</h1>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+<p>The ValidationParameter annotation is used as a parameter for
CustomValidators.</p>
<h2 id="ValidationParameterannotation-Usage">Usage</h2>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+<p></p><p>The annotation must embedded into CustomValidator annotations as a
parameter.</p>
<h2 id="ValidationParameterannotation-Parameters">Parameters</h2>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+<p><table class="confluenceTable" summary=""><tr><th colspan="1" rowspan="1"
class="confluenceTh"> Parameter </th><th colspan="1" rowspan="1"
class="confluenceTh"> Required </th><th colspan="1" rowspan="1"
class="confluenceTh"> Default </th><th colspan="1" rowspan="1"
class="confluenceTh"> Notes </th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">name</td><td colspan="1" rowspan="1"
class="confluenceTd">yes</td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd">parameter name.</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">value</td><td colspan="1" rowspan="1"
class="confluenceTd">yes</td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd">parameter value.</td></tr></table></p>
<h2 id="ValidationParameterannotation-Examples">Examples</h2>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+@CustomValidator(
+ type ="customValidatorName",
+ fieldName = "myField",
+ parameters = { @ValidationParameter( name = "paramName", value =
"paramValue" ) }
+)
+]]></script>
+</div></div>
</div>
</div>
Modified: websites/production/struts/content/docs/validations-annotation.html
==============================================================================
--- websites/production/struts/content/docs/validations-annotation.html
(original)
+++ websites/production/struts/content/docs/validations-annotation.html Tue Aug
25 07:18:20 2015
@@ -138,19 +138,50 @@ under the License.
<div class="pagecontent">
<div class="wiki-content">
- <div id="ConfluenceContent"><div class="error"><span
class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+ <div id="ConfluenceContent"><p>If you want to use several
annotations of the same type, these annotations must be nested within the
@Validations() annotation.</p>
<h2 id="ValidationsAnnotation-Usage">Usage</h2>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+<p></p><p>Used at METHOD level.</p>
<h2 id="ValidationsAnnotation-Parameters">Parameters</h2>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+<p><table class="confluenceTable"
summary=""></table></p><p><table><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"> Parameter </th><th colspan="1" rowspan="1"
class="confluenceTh"> Required </th><th colspan="1" rowspan="1"
class="confluenceTh"> Notes </th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"> requiredFields </td><td colspan="1" rowspan="1"
class="confluenceTd"> no </td></tr></tbody></table></p><p><table><tbody><tr><td
colspan="1" rowspan="1" class="confluenceTd"> Add list of
RequiredFieldValidators </td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"> customValidators </td><td colspan="1" rowspan="1"
class="confluenceTd"> no </td><td colspan="1" rowspan="1" class="confluenceTd">
Add list of CustomValidators </td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"> conversionErrorFields
</td></tr></tbody></table></p><p><table><tbody><tr><td colspan="1" rowspan="1"
class="confluenceTd"> no </td><td colspan="1" rowspan="1" class="conflu
enceTd"> Add list of ConversionErrorFieldValidators </td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"> dateRangeFields </td><td
colspan="1" rowspan="1" class="confluenceTd"> no </td><td colspan="1"
rowspan="1" class="confluenceTd"> Add list of DateRangeFieldValidators
</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> emails </td><td
colspan="1" rowspan="1" class="confluenceTd"> no </td><td colspan="1"
rowspan="1" class="confluenceTd"> Add list of EmailValidators </td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"> fieldExpressions </td><td
colspan="1" rowspan="1" class="confluenceTd"> no </td><td colspan="1"
rowspan="1" class="confluenceTd"> Add list of FieldExpressionValidators
</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> intRangeFields
</td><td colspan="1" rowspan="1" class="confluenceTd"> no </td><td colspan="1"
rowspan="1" class="confluenceTd"> Add list of IntRangeFieldValidators
</td></tr><tr><td colspan="1" rowspan="1" c
lass="confluenceTd"> requiredStrings </td><td colspan="1" rowspan="1"
class="confluenceTd"> no </td><td colspan="1" rowspan="1" class="confluenceTd">
Add list of RequiredStringValidators </td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"> stringLengthFields </td><td colspan="1" rowspan="1"
class="confluenceTd"> no </td><td colspan="1" rowspan="1" class="confluenceTd">
Add list of StringLengthFieldValidators </td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"> urls </td><td colspan="1" rowspan="1"
class="confluenceTd"> no </td><td colspan="1" rowspan="1" class="confluenceTd">
Add list of UrlValidators </td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"> visitorFields </td><td colspan="1" rowspan="1"
class="confluenceTd"> no </td><td colspan="1" rowspan="1" class="confluenceTd">
Add list of VisitorFieldValidators </td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"> regexFields </td><td colspan="1" rowspan="1"
class="confluenceTd"> no </td><
td colspan="1" rowspan="1" class="confluenceTd"> Add list of
RegexFieldValidator </td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"> expressions </td><td colspan="1" rowspan="1"
class="confluenceTd"> no </td><td colspan="1" rowspan="1" class="confluenceTd">
Add list of ExpressionValidator </td></tr></tbody></table></p>
<h2 id="ValidationsAnnotation-Examples">Examples</h2>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+@Validations(
+ requiredFields =
+ {@RequiredFieldValidator(type = ValidatorType.SIMPLE,
fieldName = "customfield", message = "You must enter a value for
field.")},
+ requiredStrings =
+ {@RequiredStringValidator(type = ValidatorType.SIMPLE,
fieldName = "stringisrequired", message = "You must enter a
value for string.")},
+ emails =
+ { @EmailValidator(type = ValidatorType.SIMPLE, fieldName =
"emailaddress", message = "You must enter a value for
email.")},
+ urls =
+ { @UrlValidator(type = ValidatorType.SIMPLE, fieldName =
"hreflocation", message = "You must enter a value for
email.")},
+ stringLengthFields =
+ {@StringLengthFieldValidator(type = ValidatorType.SIMPLE,
trim = true, minLength="10" , maxLength = "12", fieldName =
"needstringlength", message = "You must enter a
stringlength.")},
+ intRangeFields =
+ { @IntRangeFieldValidator(type = ValidatorType.SIMPLE,
fieldName = "intfield", min = "6", max = "10",
message = "bar must be between ${min} and ${max}, current value is
${bar}.")},
+ shortRangeFields =
+ { @ShortRangeFieldValidator(type = ValidatorType.SIMPLE,
fieldName = "shortfield", min = "1", max = "128",
message = "bar must be between ${min} and ${max}, current value is
${bar}.")},
+ dateRangeFields =
+ {@DateRangeFieldValidator(type = ValidatorType.SIMPLE,
fieldName = "datefield", min = "-1", max = "99",
message = "bar must be between ${min} and ${max}, current value is
${bar}.")},
+ expressions = {
+ @ExpressionValidator(expression = "foo > 1",
message = "Foo must be greater than Bar 1. Foo = ${foo}, Bar =
${bar}."),
+ @ExpressionValidator(expression = "foo > 2",
message = "Foo must be greater than Bar 2. Foo = ${foo}, Bar =
${bar}."),
+ @ExpressionValidator(expression = "foo > 3",
message = "Foo must be greater than Bar 3. Foo = ${foo}, Bar =
${bar}."),
+ @ExpressionValidator(expression = "foo > 4",
message = "Foo must be greater than Bar 4. Foo = ${foo}, Bar =
${bar}."),
+ @ExpressionValidator(expression = "foo > 5",
message = "Foo must be greater than Bar 5. Foo = ${foo}, Bar =
${bar}.")
+ }
+ )
+ public String execute() throws Exception {
+ return SUCCESS;
+ }
+]]></script>
+</div></div>
<h2 id="ValidationsAnnotation-Differentvalidationspermethod">Different
validations per method </h2>
Modified: websites/production/struts/content/docs/visitor-validator.html
==============================================================================
--- websites/production/struts/content/docs/visitor-validator.html (original)
+++ websites/production/struts/content/docs/visitor-validator.html Tue Aug 25
07:18:20 2015
@@ -140,15 +140,46 @@ under the License.
<div class="wiki-content">
<div id="ConfluenceContent">
<h1 id="visitorvalidator-Description">Description</h1>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+
+<p></p><p>
+The VisitorFieldValidator allows you to forward validation to object
+properties of your action using the object's own validation files. This
+allows you to use the ModelDriven development pattern and manage your
+validations for your models in one place, where they belong, next to your
+model classes. The VisitorFieldValidator can handle either simple Object
+properties, Collections of Objects, or Arrays.
+</p>
+
<h1 id="visitorvalidator-Parameters">Parameters</h1>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+<p></p><ul><li>fieldName - field name if plain-validator syntax is used, not
needed if field-validator syntax is used</li><li>context - the context of which
validation should take place. Optional</li><li>appendPrefix - the prefix to be
added to field. Optional </li></ul>
<h1 id="visitorvalidator-Examples">Examples</h1>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div></div>
+<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+ <validators>
+ <!-- Plain Validator Syntax -->
+ <validator type="visitor">
+ <param name="fieldName">user</param>
+ <param name="context">myContext</param>
+ <param name="appendPrefix">true</param>
+ </validator>
+
+ <!-- Field Validator Syntax -->
+ <field name="user">
+ <field-validator type="visitor">
+ <param name="context">myContext</param>
+ <param name="appendPrefix">true</param>
+ </field-validator>
+ </field>
+ </validators>
+]]></script>
+</div></div>
+<p></p><p>In the example above, if the action's getUser() method return User
object, XWork
+will look for User-myContext-validation.xml for the validators. Since
appednPrefix is true,
+every field name will be prefixed with 'user' such that if the actual field
name for 'name' is
+'user.name' </p></div>
</div>
Modified:
websites/production/struts/content/docs/visitorfieldvalidator-annotation.html
==============================================================================
---
websites/production/struts/content/docs/visitorfieldvalidator-annotation.html
(original)
+++
websites/production/struts/content/docs/visitorfieldvalidator-annotation.html
Tue Aug 25 07:18:20 2015
@@ -138,19 +138,30 @@ under the License.
<div class="pagecontent">
<div class="wiki-content">
- <div id="ConfluenceContent"><div class="error"><span
class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+ <div id="ConfluenceContent"><p>The validator allows you to forward
validator to object properties of your action
+using the objects own validator files. This allows you to use the ModelDriven
development
+pattern and manage your validations for your models in one place, where they
belong, next to
+your model classes.</p>
+
+<p>The VisitorFieldValidator can handle either simple Object properties,
Collections of Objects, or Arrays.
+The error message for the VisitorFieldValidator will be appended in front of
validator messages added
+by the validations for the Object message.</p>
<h2 id="VisitorFieldValidatorAnnotation-Usage">Usage</h2>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+<p></p><p>The annotation must be applied at method level.</p>
<h2 id="VisitorFieldValidatorAnnotation-Parameters">Parameters</h2>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
+<p><table class="confluenceTable" summary=""><tr><th colspan="1" rowspan="1"
class="confluenceTh"> Parameter </th><th colspan="1" rowspan="1"
class="confluenceTh"> Required </th><th colspan="1" rowspan="1"
class="confluenceTh"> Default </th><th colspan="1" rowspan="1"
class="confluenceTh"> Notes </th></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">message</td><td colspan="1" rowspan="1"
class="confluenceTd">yes</td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd">field error message</td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd">key</td><td colspan="1" rowspan="1"
class="confluenceTd">no</td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd">i18n key from language specific properties
file.</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">messageParams</td><td colspan="1" rowspan="1"
class="confluenceTd">no</td><td colspan="1" row
span="1" class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd">Additional params to be used to customize message - will
be evaluated against the Value Stack</td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">fieldName</td><td colspan="1" rowspan="1"
class="confluenceTd">no</td><td colspan="1" rowspan="1"
class="confluenceTd"> </td><td colspan="1" rowspan="1"
class="confluenceTd"> </td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd">shortCircuit</td><td colspan="1" rowspan="1"
class="confluenceTd">no</td><td colspan="1" rowspan="1"
class="confluenceTd">false</td><td colspan="1" rowspan="1"
class="confluenceTd">If this validator should be used as
shortCircuit.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">
context </td><td colspan="1" rowspan="1" class="confluenceTd"> no </td><td
colspan="1" rowspan="1" class="confluenceTd"> action alias </td><td colspan="1"
rowspan="1" class="confluenceTd"> Determines the conte
xt to use for validating the Object property. If not defined, the context of
the Action validation is propogated to the Object property validation. In the
case of Action validation, this context is the Action alias. </td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"> appendPrefix </td><td colspan="1"
rowspan="1" class="confluenceTd"> no </td><td colspan="1" rowspan="1"
class="confluenceTd"> true </td><td colspan="1" rowspan="1"
class="confluenceTd"> Determines whether the field name of this field validator
should be prepended to the field name of the visited field to determine the
full field name when an error occurs. For example, suppose that the bean being
validated has a "name" property. If <em>appendPrefix</em> is true, then the
field error will be stored under the field "bean.name". If
<em>appendPrefix</em> is false, then the field error will be stored under the
field "name". <br clear="none"> <img class="emoticon"
src="/images/icons/emoticons/warning.gif" hei
ght="16" width="16" alt="" style="border: 0px; align: middle;"> If you are
using the VisitorFieldValidator to validate the model from a ModelDriven
Action, you should set <em>appendPrefix</em> to false unless you are using
"model.name" to reference the properties on your model. </td></tr></table></p>
<h2 id="VisitorFieldValidatorAnnotation-Examples">Examples</h2>
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div></div>
+<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+@VisitorFieldValidator(message = "Default message", key =
"i18n.key", shortCircuit = true, context = "action alias",
appendPrefix = true)
+]]></script>
+</div></div></div>
</div>
Modified: websites/production/struts/content/docs/weblogic-61.html
==============================================================================
--- websites/production/struts/content/docs/weblogic-61.html (original)
+++ websites/production/struts/content/docs/weblogic-61.html Tue Aug 25
07:18:20 2015
@@ -131,7 +131,7 @@ under the License.
<p>This document describes why the framework doesn't work "as-is" on Weblogic
Server 6.1 and shows how to build an additional JAR that will fix the
problems.</p>
-<p><img class="emoticon emoticon-information"
src="https://cwiki.apache.org/confluence/s/en_GB-1988229788/4109/76e0dbb30bc8580e459c201f3535d84f9283a9ac.1/_/images/icons/emoticons/information.png"
data-emoticon-name="information" alt="(info)"> The service pack SP4 of
Weblogic Server 6.1 was used to test these notes.</p>
+<p><img class="emoticon emoticon-information"
src="https://cwiki.apache.org/confluence/s/en_GB/5982/f2b47fb3d636c8bc9fd0b11c0ec6d0ae18646be7.1/_/images/icons/emoticons/information.png"
data-emoticon-name="information" alt="(info)"> The service pack SP4 of
Weblogic Server 6.1 was used to test these notes.</p>
<p>The first part of this document describes the technical problems and the
theoretical solution.</p>
Modified: websites/production/struts/content/docs/webxml.html
==============================================================================
--- websites/production/struts/content/docs/webxml.html (original)
+++ websites/production/struts/content/docs/webxml.html Tue Aug 25 07:18:20 2015
@@ -138,21 +138,8 @@ under the License.
<div class="pagecontent">
<div class="wiki-content">
- <div id="ConfluenceContent"><p>The <code>web.xml</code> web
application descriptor file represents the core of the Java web application, so
it is appropriate that it is also part of the core of the Struts framework. In
the <code>web.xml</code> file, Struts defines its FilterDispatcher, the Servlet
Filter class that initializes the Struts framework and handles all requests.
This filter can contain initialization parameters that affect what, if any,
additional configuration files are loaded and how the framework should
behave.</p>
-
-<p>In addition to the FilterDispatcher, Struts also provides an
ActionContextCleanUp class that handles special cleanup tasks when other
filters, such as those used by Sitemesh, need access to an initialized Struts
framework.</p>
-
-<h2 id="web.xml-KeyInitializationParameters">Key Initialization Parameters</h2>
-
-<div class="error"><span class="error">Error formatting macro: snippet:
java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span> </div>
-
-<h2 id="web.xml-SimpleExample">Simple Example</h2>
-
-<p>Configuring <code>web.xml</code> for the framework is a matter of adding a
filter and filter-mapping.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader
panelHeader pdl" style="border-bottom-width: 1px;"><b>FilterDispatcher Example
(web.xml)</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
-<web-app id="WebApp_9" version="2.4"
+ <div id="ConfluenceContent"><p>The <code>web.xml</code> web
application descriptor file represents the core of the Java web application, so
it is appropriate that it is also part of the core of the Struts framework. In
the <code>web.xml</code> file, Struts defines its FilterDispatcher, the Servlet
Filter class that initializes the Struts framework and handles all requests.
This filter can contain initialization parameters that affect what, if any,
additional configuration files are loaded and how the framework should
behave.</p><p>In addition to the FilterDispatcher, Struts also provides an
ActionContextCleanUp class that handles special cleanup tasks when other
filters, such as those used by Sitemesh, need access to an initialized Struts
framework.</p><h2 id="web.xml-KeyInitializationParameters">Key Initialization
Parameters</h2><p></p><div class="error"><span class="error">Error formatting
macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20</span>
</div><h2 id="web.xml-SimpleExample">Simple Example</h2><p>Configuring
<code>web.xml</code> for the framework is a matter of adding a filter and
filter-mapping.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>FilterDispatcher Example (web.xml)</b></div><div class="codeContent
panelContent pdl">
+<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><web-app id="WebApp_9" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
@@ -175,47 +162,22 @@ under the License.
</web-app>
</pre>
-</div></div>
-
-<div class="confluence-information-macro confluence-information-macro-note"><p
class="title">Changed Filter Structure in Struts >= 2.1.3</p><span
class="aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body">
-<p>To split up the the dispatcher phases, FilterDispatcher is deprecated since
Struts 2.1.3. If working with older versions, you need to use</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
- ...
+</div></div><div class="confluence-information-macro
confluence-information-macro-note"><p class="title">Changed Filter Structure in
Struts >= 2.1.3</p><span class="aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>To split up the the dispatcher
phases, FilterDispatcher is deprecated since Struts 2.1.3. If working with
older versions, you need to use</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"> ...
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
...
</pre>
-</div></div>
-<p>See <a shape="rect" href="sitemesh-plugin.html">SiteMesh Plugin</a> for an
example on when to use seperate Filters for prepare and execution
phase</p></div></div>
-
-<div class="confluence-information-macro confluence-information-macro-note"><p
class="title">Why the Filter is mapped with /* and how to configure explicit
exclusions (since 2.1.7)</p><span class="aui-icon aui-icon-small
aui-iconfont-warning confluence-information-macro-icon"></span><div
class="confluence-information-macro-body">
-<p> In the example above we've mapped the Struts 2 dispatcher to
<code>/*</code>, so Struts 2 has a crack at all incoming requests. This is
because Struts 2 serves static content from its jar files, including Dojo
JavaScript files (if using S2.0, or the Dojo plugin in S2.1+) and FreeMarker
templates for the Struts 2 tags that produce HTML.</p>
-
-<p> If we change the filter mapping to something else, for example
<code>/*.html</code>, we must take this in to account and extract the content
that would normally be served from the Struts 2 jar files, or some other
solution.</p>
-
-<p> Since Struts 2.1.7, you are able to provide a comma seperated list of
patterns for which when matching against the<br clear="none">
-request URL the Filter will just pass by. This is done via the configuration
option struts.action.excludePattern, for example in your struts.xml</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
-<struts>
+</div></div><p>See <a shape="rect" href="sitemesh-plugin.html">SiteMesh
Plugin</a> for an example on when to use seperate Filters for prepare and
execution phase</p></div></div><div class="confluence-information-macro
confluence-information-macro-note"><p class="title">Why the Filter is mapped
with /* and how to configure explicit exclusions (since 2.1.7)</p><span
class="aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>In the example above we've mapped
the Struts 2 dispatcher to <code>/*</code>, so Struts 2 has a crack at all
incoming requests. This is because Struts 2 serves static content from its jar
files, including Dojo JavaScript files (if using S2.0, or the Dojo plugin in
S2.1+) and FreeMarker templates for the Struts 2 tags that produce
HTML.</p><p>If we change the filter mapping to something else, for example
<code>/*.html</code>, we must take this in to account and extract the content t
hat would normally be served from the Struts 2 jar files, or some other
solution.</p><p>Since Struts 2.1.7, you are able to provide a comma seperated
list of patterns for which when matching against the<br clear="none"> request
URL the Filter will just pass by. This is done via the configuration option
struts.action.excludePattern, for example in your struts.xml</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><struts>
<constant name="struts.action.excludePattern"
value=".*unfiltered.*,.*\\.nofilter"/>
...
</struts>
</pre>
-</div></div></div></div>
-
-<h2 id="web.xml-TaglibExample">Taglib Example </h2>
-
-<p>Typically, configuring a taglib is neither required nor recommended. The
taglib is included in <code>struts-core.jar</code>, and the container will
discover it automatically.</p>
-
-<p><img class="emoticon emoticon-tick"
src="https://cwiki.apache.org/confluence/s/en_GB/5982/f2b47fb3d636c8bc9fd0b11c0ec6d0ae18646be7.1/_/images/icons/emoticons/check.png"
data-emoticon-name="tick" alt="(tick)"> If, for some reason, a taglib
configuration is needed within web.xml, extract the TLD file from the
<code>struts-core.jar</code> <code>META-INF</code> folder, and add a
<code>taglib</code> element to the <code>web.xml</code>.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
- <!-- ... -->
+</div></div></div></div><h2 id="web.xml-TaglibExample">Taglib
Example</h2><p>Typically, configuring a taglib is neither required nor
recommended. The taglib is included in <code>struts-core.jar</code>, and the
container will discover it automatically.</p><p><img class="emoticon
emoticon-tick"
src="https://cwiki.apache.org/confluence/s/en_GB/5982/f2b47fb3d636c8bc9fd0b11c0ec6d0ae18646be7.1/_/images/icons/emoticons/check.png"
data-emoticon-name="tick" alt="(tick)"> If, for some reason, a taglib
configuration is needed within web.xml, extract the TLD file from the
<code>struts-core.jar</code> <code>META-INF</code> folder, and add a
<code>taglib</code> element to the <code>web.xml</code>.</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"> <!-- ... -->
</welcome-file-list>
<taglib>
@@ -224,17 +186,8 @@ request URL the Filter will just pass by
</taglib>
</web-app>
</pre>
-</div></div>
-
-<h2 id="web.xml-CustomFileManagerandFileManagerFactoryimplementations">Custom
FileManager and FileManagerFactory implementations</h2>
-
-<p>If there is a need to support an App Server's specific file system (eg. VFS
in JBoss), you can implement your own version of FileManager. But it must be
registered at "the beginning" to support bootstrap of the whole framework.</p>
-
-<p>To register your own FileManger you can do it with <init-param/> as
below:</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
-<filter>
+</div></div><h2
id="web.xml-CustomFileManagerandFileManagerFactoryimplementations">Custom
FileManager and FileManagerFactory implementations</h2><p>If there is a need to
support an App Server's specific file system (eg. VFS in JBoss), you can
implement your own version of FileManager. But it must be registered at "the
beginning" to support bootstrap of the whole framework.</p><p>To register your
own FileManger you can do it with <init-param/> as below:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
@@ -243,13 +196,8 @@ request URL the Filter will just pass by
</init-param>
</filter>
</pre>
-</div></div>
-
-<p>You can as well register your own FileManagerFactory with
<init-param/>, see example:</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
-<filter>
+</div></div><p>You can as well register your own FileManagerFactory with
<init-param/>, see example:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
@@ -258,9 +206,7 @@ request URL the Filter will just pass by
</init-param>
</filter>
</pre>
-</div></div>
-
-<p>Take a look on default implementations - DefaultFileManager.java and
DefaultFileManagerFactory.java to understand how and why.</p></div>
+</div></div><p>Take a look on default implementations -
DefaultFileManager.java and DefaultFileManagerFactory.java to understand how
and why.</p></div>
</div>
Modified:
websites/production/struts/content/docs/why-is-my-action-returning-input-when-the-form-is-filled-out-correctly.html
==============================================================================
---
websites/production/struts/content/docs/why-is-my-action-returning-input-when-the-form-is-filled-out-correctly.html
(original)
+++
websites/production/struts/content/docs/why-is-my-action-returning-input-when-the-form-is-filled-out-correctly.html
Tue Aug 25 07:18:20 2015
@@ -127,11 +127,11 @@ under the License.
<div class="wiki-content">
<div id="ConfluenceContent"><p>The token "input" is returned when
validation fails, and the Action class is never invoked. If the validation
messages are not displaying, the most likely cause is that a property is being
validated that is not present on the page (so there is no where to display the
message). </p>
-<p><img class="emoticon emoticon-tick"
src="https://cwiki.apache.org/confluence/s/en_GB-1988229788/4109/76e0dbb30bc8580e459c201f3535d84f9283a9ac.1/_/images/icons/emoticons/check.png"
data-emoticon-name="tick" alt="(tick)"> If the validator is being attached to
the Action class, note that a subclass will inherit the validations of its
superclass.</p>
+<p><img class="emoticon emoticon-tick"
src="https://cwiki.apache.org/confluence/s/en_GB/5982/f2b47fb3d636c8bc9fd0b11c0ec6d0ae18646be7.1/_/images/icons/emoticons/check.png"
data-emoticon-name="tick" alt="(tick)"> If the validator is being attached to
the Action class, note that a subclass will inherit the validations of its
superclass.</p>
-<p><img class="emoticon emoticon-tick"
src="https://cwiki.apache.org/confluence/s/en_GB-1988229788/4109/76e0dbb30bc8580e459c201f3535d84f9283a9ac.1/_/images/icons/emoticons/check.png"
data-emoticon-name="tick" alt="(tick)"> Try submitting the form in <a
shape="rect" href="debugging.html">debugging mode</a> to see if there are any
orphan field validation errors.</p>
+<p><img class="emoticon emoticon-tick"
src="https://cwiki.apache.org/confluence/s/en_GB/5982/f2b47fb3d636c8bc9fd0b11c0ec6d0ae18646be7.1/_/images/icons/emoticons/check.png"
data-emoticon-name="tick" alt="(tick)"> Try submitting the form in <a
shape="rect" href="debugging.html">debugging mode</a> to see if there are any
orphan field validation errors.</p>
-<p><img class="emoticon emoticon-tick"
src="https://cwiki.apache.org/confluence/s/en_GB-1988229788/4109/76e0dbb30bc8580e459c201f3535d84f9283a9ac.1/_/images/icons/emoticons/check.png"
data-emoticon-name="tick" alt="(tick)"> Type conversion errors may also cause
a return to "input".</p></div>
+<p><img class="emoticon emoticon-tick"
src="https://cwiki.apache.org/confluence/s/en_GB/5982/f2b47fb3d636c8bc9fd0b11c0ec6d0ae18646be7.1/_/images/icons/emoticons/check.png"
data-emoticon-name="tick" alt="(tick)"> Type conversion errors may also cause
a return to "input".</p></div>
</div>
Modified:
websites/production/struts/content/docs/why-would-we-want-to-create-action-objects-from-the-spring-configuration.html
==============================================================================
---
websites/production/struts/content/docs/why-would-we-want-to-create-action-objects-from-the-spring-configuration.html
(original)
+++
websites/production/struts/content/docs/why-would-we-want-to-create-action-objects-from-the-spring-configuration.html
Tue Aug 25 07:18:20 2015
@@ -129,7 +129,7 @@ under the License.
<p>We might also want to apply more complex AOP or Spring-enabled
technologies, such as Acegi, to our Action objects. </p>
-<p><img class="emoticon emoticon-light-on"
src="https://cwiki.apache.org/confluence/s/en_GB-1988229788/4109/76e0dbb30bc8580e459c201f3535d84f9283a9ac.1/_/images/icons/emoticons/lightbulb_on.png"
data-emoticon-name="light-on" alt="(lightbulb)"> For more, see <a shape="rect"
href="spring-plugin.html#SpringPlugin-InitializingActionsfromSpring">Initializing
Actions from Spring</a>.</p></div>
+<p><img class="emoticon emoticon-light-on"
src="https://cwiki.apache.org/confluence/s/en_GB/5982/f2b47fb3d636c8bc9fd0b11c0ec6d0ae18646be7.1/_/images/icons/emoticons/lightbulb_on.png"
data-emoticon-name="light-on" alt="(lightbulb)"> For more, see <a shape="rect"
href="spring-plugin.html">Initializing Actions from Spring</a>.</p></div>
</div>