http://git-wip-us.apache.org/repos/asf/struts-site/blob/b16cc4ef/content/docs/validation.html ---------------------------------------------------------------------- diff --git a/content/docs/validation.html b/content/docs/validation.html index 51e6714..c08399f 100644 --- a/content/docs/validation.html +++ b/content/docs/validation.html @@ -34,20 +34,6 @@ under the License. color: #666; } </style> - <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> - <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> - <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushCss.js' type='text/javascript'></script> - <script type="text/javascript"> - SyntaxHighlighter.defaults['toolbar'] = false; - SyntaxHighlighter.all(); - </script> <script type="text/javascript" language="javascript"> var hide = null; var show = null; @@ -139,47 +125,7 @@ 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.rbtoc1499928416993 {padding: 0px;} -div.rbtoc1499928416993 ul {list-style: none;margin-left: 0px;} -div.rbtoc1499928416993 li {margin-left: 0px;padding-left: 0px;} - -/*]]>*/</style></p><div class="toc-macro rbtoc1499928416993"> -<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><p></p><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>The following list shows the default validators included in the framework and is an example of the syntax used to declare our own validators.<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[ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE validators PUBLIC - "-//Apache Struts//XWork Validator Definition 1.0//EN" - "http://struts.apache.org/dtds/xwork-validator-definition-1.0.dtd"> - -<validators> - <validator name="required" class="com.opensymphony.xwork2.validator.validators.RequiredFieldValidator"/> - <validator name="requiredstring" class="com.opensymphony.xwork2.validator.validators.RequiredStringValidator"/> - <validator name="int" class="com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator"/> - <validator name="long" class="com.opensymphony.xwork2.validator.validators.LongRangeFieldValidator"/> - <validator name="short" class="com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator"/> - <validator name="double" class="com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator"/> - <validator name="date" class="com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator"/> - <validator name="expression" class="com.opensymphony.xwork2.validator.validators.ExpressionValidator"/> - <validator name="fieldexpression" class="com.opensymphony.xwork2.validator.validators.FieldExpressionValidator"/> - <validator name="email" class="com.opensymphony.xwork2.validator.validators.EmailValidator"/> - <validator name="creditcard" class="com.opensymphony.xwork2.validator.validators.CreditCardValidator"/> - <validator name="url" class="com.opensymphony.xwork2.validator.validators.URLValidator"/> - <validator name="visitor" class="com.opensymphony.xwork2.validator.validators.VisitorFieldValidator"/> - <validator name="conversion" class="com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator"/> - <validator name="stringlength" class="com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator"/> - <validator name="regex" class="com.opensymphony.xwork2.validator.validators.RegexFieldValidator"/> - <validator name="conditionalvisitor" class="com.opensymphony.xwork2.validator.validators.ConditionalVisitorFieldValidator"/> -</validators> -]]></script> -</div></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 sh ape="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="codeContent panelContent pdl"> -<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><interceptor-stack name="defaultStack"> + <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><parameter ac:name="minLevel">2</parameter><parameter ac:name="outline">true</parameter><parameter ac:name="style">none</parameter></p><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 Validation</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><parameter >ac:name="title">Note</parameter><rich-text-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 >field-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></rich-text-body><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-validator.html">short validator</a></li><l i><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><plain-text-body>{snippet:id=javadoc|javadoc=true|url=com.opensymphony.xwork2.validator/ValidatorFactory.java}</plain-text-body>The following list shows the default validators included in the framework and is an example of the syntax used to declare our own validators.<plain-text-body>{snippet:lang=xml|url=struts2/core/src/main/resources/com/opensymphony/xwork2/validator/validators/default.xml}</plain-text-body></p><parameter ac:name="title">Struts 2.1 and Prior</parameter><rich-text-body><p>The <code>validators.xml</code> used to reference a DTD hosted by Opensymphony, the original loca tion 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></rich-text-body><parameter ac:name="title">Struts 2.0.7 and Prior</parameter><rich-text-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></rich-text-body><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><parameter ac:name="lang">xml</parameter><plain-text-body><interceptor-stack name="defaultStack"> ... <interceptor-ref name="validation"> <param name="excludeMethods">input,back,cancel,browse</param> @@ -188,154 +134,16 @@ all the validators you intend to use.</p>The following list shows the default va <param name="excludeMethods">input,back,cancel,browse</param> </interceptor-ref> </interceptor-stack> -</pre> -</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><p></p><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></p><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></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></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></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> +</plain-text-body><p>Beginning with version 2.0.4 Struts provides an extension to XWork's <code>com.opensymphony.xwork2.validator.ValidationInterceptor</code> interceptor.</p><parameter ac:name="lang">xml</parameter><plain-text-body><interceptor name="validation" class="org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor"/> +</plain-text-body><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><plain-text-body>{snippet:id=fieldValidators|javadoc=true|url=com.opensymphony.xwork2.validator/ValidatorFactory.java}</plain-text-body><plain-text-body>{snippet:id=nonFieldValidators|javadoc=true|url=com.opensymphony.xwork2.validator/ValidatorFactory.java}</plain-text-body></p><h3 id="Validation-Notes">Notes</h3><p><plain-text-body>{snippet:id=validatorsNote|javadoc=true|url=com.opensymphony.xwork2.validator/ValidatorFactory.java}</plain-text-body></p><h2 id="Validation-DefiningValidationRules">Defining Validation Rules</h2><p><plain-text-body>{snippet:id=validationRules1|javadoc=true|url=com.opensymphony.xwork2.validator/ValidatorFactory.java}</plain-text-body><plain-text-body>{snippet:id=exValidationRules1|lang= xml|javadoc=true|url=com.opensymphony.xwork2.validator/ValidatorFactory.java}</plain-text-body><plain-text-body>{snippet:id=validationRules2|javadoc=true|url=com.opensymphony.xwork2.validator/ValidatorFactory.java}</plain-text-body></p><rich-text-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></rich-text-body><h2 id="Validation-LocalizingandParameterizingMessages">Localizing and Parameterizing Messages</h2><p><plain-text-body>{snippet:id=validationRules3|javadoc=true|url=com.opensymphony.xwork2.validator/ValidatorFactory.java}</plain-text-body><plain-text-body>{snippet:id=exValidationRules3|javadoc=true|lang=xml|url=com.opensymphony.xwork2.validator/ValidatorFactory.java}</plain-text-body><plain-text-body>{snippet:id=validationRules4|javadoc=true|url=com.opensymphony.xwork2.validator/ValidatorFactory.java}</plain-text-body><plain-text-body>{snippet :id=exValidationRules4|javadoc=true|lang=xml|url=com.opensymphony.xwork2.validator/ValidatorFactory.java}</plain-text-body></p><h2 id="Validation-ValidatorFlavor">Validator Flavor</h2><p><plain-text-body>{snippet:id=validatorFlavours|javadoc=true|url=com.opensymphony.xwork2.validator/Validator.java}</plain-text-body></p><h2 id="Validation-Non-FieldValidatorVsField-Validatorvalidatortypes">Non-Field Validator Vs Field-Validator <parameter ac:name="">validatortypes</parameter></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><parameter ac:name="">xml</parameter><plain-text-body><validator type="expression> <param name="expression">foo gt bar</param> <message>foo must be great than bar.</message> </validator> -</pre> -</div></div><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="required"> +</plain-text-body><parameter ac:name="">xml</parameter><plain-text-body><validator type="required"> <param name="fieldName">bar</param> <message>You must enter a value for bar.</message> </validator> -</pre> -</div></div><p><strong>field-validator</strong>: The <field-validator> elements are basically the same as the <validator> elements except that they inherit the fieldName attribute from the enclosing <field> element. FieldValidators defined within a <field-validator> element will have their fieldName automatically filled with the value of the parent <field> element's fieldName attribute. The reason for this structure is to conveniently group the validators for a particular field under one element, otherwise the fieldName attribute would have to be repeated, over and over, for each individual <validator>.</p><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>It is always better to defined field-validator inside a <field> tag instead of using a <validator> tag and sup plying fieldName as its param as the xml code itself is clearer (grouping of field is clearer)</p></div></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>Note that you should only use FieldValidators (not plain Validators) within a block. A plain Validator inside a <field> will not be allowed and would generate error when parsing the xml, as it is not allowed in the defined dtd (xwork-validator-1.0.2.dtd)</p></div></div><p>Declaring a FieldValidator using the <field-validator> syntax:</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;"><field name="email_address"> +</plain-text-body><p><strong>field-validator</strong>: The <field-validator> elements are basically the same as the <validator> elements except that they inherit the fieldName attribute from the enclosing <field> element. FieldValidators defined within a <field-validator> element will have their fieldName automatically filled with the value of the parent <field> element's fieldName attribute. The reason for this structure is to conveniently group the validators for a particular field under one element, otherwise the fieldName attribute would have to be repeated, over and over, for each individual <validator>.</p><rich-text-body><p>It is always better to defined field-validator inside a <field> tag instead of using a <validator> tag and supplying fieldName as its param as the xml code itself is clearer (grouping of field is clearer)</p></rich-text-body><rich-text-body><p>Note that you should only use FieldValidators (not plain Validator s) within a block. A plain Validator inside a <field> will not be allowed and would generate error when parsing the xml, as it is not allowed in the defined dtd (xwork-validator-1.0.2.dtd)</p></rich-text-body><p>Declaring a FieldValidator using the <field-validator> syntax:</p><parameter ac:name="">xml</parameter><plain-text-body><field name="email_address"> <field-validator type="required"> <message>You cannot leave the email address field empty.</message> </field-validator> @@ -343,9 +151,7 @@ to implement.</p><h2 id="Validation-Non-FieldValidatorVsField-Validatorvalidator <message>The email address you entered is not valid.</message> </field-validator> </field> -</pre> -</div></div><p>The choice is yours. It's perfectly legal to only use elements without the elements and set the fieldName attribute for each of them. The following are effectively equal:</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;"><field name="email_address"> +</plain-text-body><p>The choice is yours. It's perfectly legal to only use elements without the elements and set the fieldName attribute for each of them. The following are effectively equal:</p><parameter ac:name="">xml</parameter><plain-text-body><field name="email_address"> <field-validator type="required"> <message>You cannot leave the email address field empty.</message> </field-validator> @@ -362,115 +168,7 @@ to implement.</p><h2 id="Validation-Non-FieldValidatorVsField-Validatorvalidator <param name="fieldName">email_address</param> <message>The email address you entered is not valid.</message> </validator> -</pre> -</div></div><h2 id="Validation-Short-CircuitingValidator">Short-Circuiting Validator</h2><p></p><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></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> +</plain-text-body><h2 id="Validation-Short-CircuitingValidator">Short-Circuiting Validator</h2><p><plain-text-body>{snippet:id=shortCircuitingValidators1|javadoc=true|url=com.opensymphony.xwork2.validator/Validator.java}</plain-text-body><plain-text-body>{snippet:id=exShortCircuitingValidators|lang=xml|javadoc=true|url=com.opensymphony.xwork2.validator/Validator.java}</plain-text-body><plain-text-body>{snippet:id=shortCircuitingValidators2|javadoc=true|url=com.opensymphony.xwork2.validator/Validator.java}</plain-text-body><plain-text-body>{snippet:id=scAndValidatorFlavours1|1=javadoc|javadoc=true|url=com.opensymphony.xwork2.validator/Validator.java}</plain-text-body><plain-text-body>{snippet:id=exScAndValidatorFlavours|lang=xml|javadoc=true|url=com.opensymphony.xwork2.validator/Validator.java}</plain-text-body><plain-text-body>{snippet:id=scAndValidatorFlavours2|1=javadoc|javadoc=true|url=com.opensymphony.xwork2.validator/Validator.java}</plain-text-body></p><h2 id="Validation-HowVa lidatorsofanActionareFound">How Validators of an Action are Found</h2><p><plain-text-body>{snippet:id=howXworkFindsValidatorForAction|javadoc=true|url=com.opensymphony.xwork2.validator/Validator.java}</plain-text-body></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">
http://git-wip-us.apache.org/repos/asf/struts-site/blob/b16cc4ef/content/docs/validationparameter-annotation.html ---------------------------------------------------------------------- diff --git a/content/docs/validationparameter-annotation.html b/content/docs/validationparameter-annotation.html index 57e673d..e0351ad 100644 --- a/content/docs/validationparameter-annotation.html +++ b/content/docs/validationparameter-annotation.html @@ -155,7 +155,7 @@ under the License. <h2 id="ValidationParameterannotation-Examples">Examples</h2> <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[ +<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ @CustomValidator( type ="customValidatorName", fieldName = "myField", http://git-wip-us.apache.org/repos/asf/struts-site/blob/b16cc4ef/content/docs/validations-annotation.html ---------------------------------------------------------------------- diff --git a/content/docs/validations-annotation.html b/content/docs/validations-annotation.html index bcb5692..de73090 100644 --- a/content/docs/validations-annotation.html +++ b/content/docs/validations-annotation.html @@ -34,20 +34,6 @@ under the License. color: #666; } </style> - <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> - <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> - <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script> - <script src='https://struts.apache.org/highlighter/js/shBrushCss.js' type='text/javascript'></script> - <script type="text/javascript"> - SyntaxHighlighter.defaults['toolbar'] = false; - SyntaxHighlighter.all(); - </script> <script type="text/javascript" language="javascript"> var hide = null; var show = null; @@ -139,72 +125,36 @@ under the License. <div class="pagecontent"> <div class="wiki-content"> - <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> + <div id="ConfluenceContent"><plain-text-body>{snippet:id=description|javadoc=true|url=com.opensymphony.xwork2.validator.annotations.Validations}</plain-text-body> <h2 id="ValidationsAnnotation-Usage">Usage</h2> -<p></p><p>Used at METHOD level.</p> +<plain-text-body>{snippet:id=usage|javadoc=true|url=com.opensymphony.xwork2.validator.annotations.Validations}</plain-text-body> <h2 id="ValidationsAnnotation-Parameters">Parameters</h2> -<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> +<plain-text-body>{snippet:id=parameters|javadoc=true|url=com.opensymphony.xwork2.validator.annotations.Validations}</plain-text-body> <h2 id="ValidationsAnnotation-Examples">Examples</h2> -<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}.")}, - longRangeFields = - { @LongRangeFieldValidator(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> +<plain-text-body>{snippet:id=example|javadoc=true|lang=java|url=com.opensymphony.xwork2.validator.annotations.Validations}</plain-text-body> <h2 id="ValidationsAnnotation-Differentvalidationspermethod">Different validations per method </h2> -<div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Different validations per method is NOT supported for client-side validation!</p></div></div> +<rich-text-body><p>Different validations per method is NOT supported for client-side validation!</p></rich-text-body> <p>To use different validations per method, the validateAnnotatedMethodOnly property must be set on the validation interceptor.</p> -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> +<plain-text-body> <interceptor-ref name="validation"> <param name="validateAnnotatedMethodOnly">true</param> <param name="excludeMethods">input,back,cancel,browse</param> </interceptor-ref> -</pre> -</div></div> +</plain-text-body> <p>Here's a complete example of updating the default stack:</p> -<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;"> +<plain-text-body> <package name="default" extends="struts-default"> <interceptors> <interceptor-stack name="content"> @@ -237,8 +187,7 @@ under the License. <default-interceptor-ref name="default"/> </package> </struts> -</pre> -</div></div></div> +</plain-text-body></div> </div> http://git-wip-us.apache.org/repos/asf/struts-site/blob/b16cc4ef/content/docs/version-notes-2513.html ---------------------------------------------------------------------- diff --git a/content/docs/version-notes-2513.html b/content/docs/version-notes-2513.html new file mode 100644 index 0000000..cd250b9 --- /dev/null +++ b/content/docs/version-notes-2513.html @@ -0,0 +1,169 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> + <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> + <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script> + <script src='https://struts.apache.org/highlighter/js/shBrushCss.js' type='text/javascript'></script> + <script type="text/javascript"> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); + </script> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>Version Notes 2.5.13</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="migration-guide.html">Migration Guide</a> > <a href="version-notes-2513.html">Version Notes 2.5.13</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="https://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">Version Notes 2.5.13</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=73634549"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=73634549">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=73634549"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=73634549">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=73634549"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=73634549">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><p><img class="emoticon emoticon-tick" src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/check.png" data-emoticon-name="tick" alt="(tick)"> These are the notes for the Struts 2.5.13 distribution.</p><p><img class="emoticon emoticon-tick" src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/check.png" data-emoticon-name="tick" alt="(tick)"> For prior notes in this release series, see <a shape="rect" href="version-notes-2512.html">Version Notes 2.5.12</a></p><ul><li>If you are a Maven user, you might want to get started using the <a shape="rect" href="struts-2-maven-archetypes.html">Maven Archetype</a>.</li></ul><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Maven Dependency</b></div><div class="codeContent panelContent pdl "> +<pre class="brush: bash; gutter: false; theme: Confluence" style="font-size:12px;"><dependency> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-core</artifactId> + <version>2.5.13</version> +</dependency> +</pre> +</div></div><p>You can also use Struts Archetype Catalog like below</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Struts Archetype Catalog</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: text; gutter: false; theme: Confluence" style="font-size:12px;">mvn archetype:generate -DarchetypeCatalog=http://struts.apache.org/</pre> +</div></div><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Staging Repository</b></div><div class="codeContent panelContent pdl"> +<pre class="brush: bash; gutter: false; theme: Confluence" style="font-size:12px;"><repositories> + <repository> + <id>apache.nexus</id> + <name>ASF Nexus Staging</name> + <url>https://repository.apache.org/content/groups/staging/</url> + </repository> +</repositories></pre> +</div></div><h2 id="VersionNotes2.5.13-InternalChanges">Internal Changes</h2><ul><li><img class="emoticon emoticon-warning" src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/warning.png" data-emoticon-name="warning" alt="(warning)"> A regular expression Denial of Service when using URLValidator (similar to S2-044 & S2-047), see <a shape="rect" href="s2-050.html">S2-050</a></li><li><img class="emoticon emoticon-warning" src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/warning.png" data-emoticon-name="warning" alt="(warning)"> A remote attacker may create a DoS attack by sending crafted xml request when using the Struts REST plugin, see <a shape="rect" href="s2-051.html">S2-051</a></li><li><img class="emoticon emoticon-warning" src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2 a2.1/_/images/icons/emoticons/warning.png" data-emoticon-name="warning" alt="(warning)"> Possible Remote Code Execution attack when using the Struts REST plugin with XStream handler to handle XML payloads, see <a shape="rect" href="s2-052.html">S2-052</a></li></ul><h2 id="VersionNotes2.5.13-Bug">Bug</h2><ul><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4176">WW-4176</a>] - Struts2 JSON Plugin: Send Map with Strings as Key to JSON Action is ignored, Numeric Keys will work and mapped</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4813">WW-4813</a>] - NP with TextProvider and wildcardmapping</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4817">WW-4817</a>] - Threads get blocked due to unnecessary synchronization in OgnlRuntime</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4818">WW-4818</a>] - Default Multipart validation regex is invalid</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4827">WW-4827</a>] - Not fully initialized ObjectFactory tries to create beans</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4828">WW-4828</a>] - <a shape="rect" class="external-link" href="http://struts.apache.org/dtds/struts-2.5.dtd">http://struts.apache.org/dtds/struts-2.5.dtd</a> missing</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4829">WW-4829</a>] - Set a global resource bundle in class</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4830">WW-4830</a>] - Override TextProvider doesnot work in struts 2.5.12</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4831">WW-4831</a>] - Array-of-null parameters are converted to string "null"</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4839">WW-4839</a>] - JakartaStreamMultiPartRequest Should Honor "struts.multipart.maxSize"</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4840">WW-4840</a>] - Build Fails Due to Unused com.sun Import</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4841">WW-4841</a>] - Struts2.5.12 - NPE in DeligatingValidatorContext</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4842">WW-4842</a>] - Struts 2 Fails to Initialize with JRebel</li></ul><h2 id="VersionNotes2.5.13-Improvement">Improvement</h2><ul><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4808">WW-4808</a>] - Allow define more than one Action suffix</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4823">WW-4823</a>] - Remove jQuery from debugg ing interceptor views</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4824">WW-4824</a>] - update dependencies page on the struts site</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4834">WW-4834</a>] - Improve RegEx used to validate URLs</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4835">WW-4835</a>] - Make REST ContentHandlers configurable</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4838">WW-4838</a>] - expose Freemarker incompatible_improvements into FreemarkerManager and StrutsBeansWrapper</li></ul><h2 id="VersionNotes2.5.13-Dependency">Dependency</h2><ul><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4819">WW-4819</a>] - Upgrade Commons Collections to 3.2.2</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/ WW-4821">WW-4821</a>] - Upgrade Commons IO to 2.5</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4826">WW-4826</a>] - Upgrade to ASM version 5.2</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4833">WW-4833</a>] - Upgrade to OGNL 3.1.15</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4836">WW-4836</a>] - Upgrade xstream to the latest version</li><li>[<a shape="rect" class="external-link" href="https://issues.apache.org/jira/browse/WW-4844">WW-4844</a>] - Upgrade to struts-master 11</li></ul><p> </p><p>Issue Detail</p><ul><li><a shape="rect" class="external-link" href="https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=12311041&version=12341116">JIRA Release Notes 2.5.13</a></li></ul><h2 id="VersionNotes2.5.13-IssueList">Issue List</h2><ul><li><a shape="rect" class="external-link" href="https://issues.apache.org/jira/issues/ ?filter=12341742">Struts 2.5.13 DONE</a></li><li><a shape="rect" class="external-link" href="https://issues.apache.org/jira/issues/?filter=12335667">Struts 2.5.x TODO</a></li></ul><h2 id="VersionNotes2.5.13-Otherresources">Other resources</h2><ul><li><a shape="rect" class="external-link" href="http://www.mail-archive.com/commits%40struts.apache.org/" rel="nofollow">Commit Logs</a></li><li><a shape="rect" class="external-link" href="https://git-wip-us.apache.org/repos/asf?p=struts.git;a=tree;h=refs/heads/develop;hb=develop">Source Code Repository</a></li></ul><div><span style="font-size: 24.0px;line-height: 30.0px;"><br clear="none"></span></div><div><span style="font-size: 24.0px;line-height: 30.0px;background-color: rgb(245,245,245);"><br clear="none"></span></div></div> + </div> + + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/struts-site/blob/b16cc4ef/content/docs/visitor-validator.html ---------------------------------------------------------------------- diff --git a/content/docs/visitor-validator.html b/content/docs/visitor-validator.html index d4fe7f0..8fdba4e 100644 --- a/content/docs/visitor-validator.html +++ b/content/docs/visitor-validator.html @@ -158,7 +158,7 @@ properties, Collections of Objects, or Arrays. <h1 id="visitorvalidator-Examples">Examples</h1> <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[ +<script class="brush: xml; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ <validators> <!-- Plain Validator Syntax --> <validator type="visitor"> http://git-wip-us.apache.org/repos/asf/struts-site/blob/b16cc4ef/content/docs/visitorfieldvalidator-annotation.html ---------------------------------------------------------------------- diff --git a/content/docs/visitorfieldvalidator-annotation.html b/content/docs/visitorfieldvalidator-annotation.html index 154f634..ede46a0 100644 --- a/content/docs/visitorfieldvalidator-annotation.html +++ b/content/docs/visitorfieldvalidator-annotation.html @@ -159,7 +159,7 @@ by the validations for the Object message.</p> <h2 id="VisitorFieldValidatorAnnotation-Examples">Examples</h2> <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[ +<script class="brush: java; gutter: false; theme: Confluence" type="syntaxhighlighter"><![CDATA[ @VisitorFieldValidator(message = "Default message", key = "i18n.key", shortCircuit = true, context = "action alias", appendPrefix = true) ]]></script> </div></div></div>