| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"/> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"/> |
| <meta name="Date-Revision-yyyymmdd" content="20140918"/> |
| <meta http-equiv="Content-Language" content="en"/> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| |
| <title>Annotations</title> |
| |
| <link href="//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,400italic,600italic,700italic" rel="stylesheet" type="text/css"> |
| <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> |
| <link href="/css/main.css" rel="stylesheet"> |
| <link href="/css/custom.css" rel="stylesheet"> |
| <link href="/css/syntax.css" rel="stylesheet"> |
| |
| <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> |
| <script type="text/javascript" src="/bootstrap/js/bootstrap.js"></script> |
| <script type="text/javascript" src="/js/community.js"></script> |
| |
| <!-- Matomo --> |
| <script> |
| var _paq = window._paq = window._paq || []; |
| /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ |
| /* We explicitly disable cookie tracking to avoid privacy issues */ |
| _paq.push(['disableCookies']); |
| _paq.push(['trackPageView']); |
| _paq.push(['enableLinkTracking']); |
| (function() { |
| var u="//analytics.apache.org/"; |
| _paq.push(['setTrackerUrl', u+'matomo.php']); |
| _paq.push(['setSiteId', '41']); |
| var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; |
| g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); |
| })(); |
| </script> |
| <!-- End Matomo Code --> |
| </head> |
| <body> |
| |
| <a href="https://github.com/apache/struts" class="github-ribbon"> |
| <img decoding="async" loading="lazy" style="position: absolute; right: 0; border: 0;" width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_red_aa0000.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"> |
| </a> |
| |
| <header> |
| <nav> |
| <div role="navigation" class="navbar navbar-default navbar-fixed-top"> |
| <div class="container"> |
| <div class="navbar-header"> |
| <button type="button" data-toggle="collapse" data-target="#struts-menu" class="navbar-toggle"> |
| Menu |
| <span class="sr-only">Toggle navigation</span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| <a href="/index.html" class="navbar-brand logo"><img src="/img/struts-logo.svg"></a> |
| </div> |
| <div id="struts-menu" class="navbar-collapse collapse"> |
| <ul class="nav navbar-nav"> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Home<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/index.html">Welcome</a></li> |
| <li><a href="/download.cgi">Download</a></li> |
| <li><a href="/releases.html">Releases</a></li> |
| <li><a href="/announce-2023.html">Announcements</a></li> |
| <li><a href="http://www.apache.org/licenses/">License</a></li> |
| <li><a href="https://www.apache.org/foundation/thanks.html">Thanks!</a></li> |
| <li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li> |
| <li><a href="https://privacy.apache.org/policies/privacy-policy-public.html">Privacy Policy</a></li> |
| </ul> |
| </li> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Support<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/mail.html">User Mailing List</a></li> |
| <li><a href="https://issues.apache.org/jira/browse/WW">Issue Tracker</a></li> |
| <li><a href="/security.html">Reporting Security Issues</a></li> |
| <li><a href="/commercial-support.html">Commercial Support</a></li> |
| <li class="divider"></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/Migration+Guide">Version Notes</a></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/Security+Bulletins">Security Bulletins</a></li> |
| <li class="divider"></li> |
| <li><a href="/maven/project-info.html">Maven Project Info</a></li> |
| <li><a href="/maven/struts2-core/dependencies.html">Struts Core Dependencies</a></li> |
| <li><a href="/maven/struts2-plugins/modules.html">Plugin Dependencies</a></li> |
| </ul> |
| </li> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Documentation<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/birdseye.html">Birds Eye</a></li> |
| <li><a href="/primer.html">Key Technologies</a></li> |
| <li><a href="/kickstart.html">Kickstart FAQ</a></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/Home">Wiki</a></li> |
| <li class="divider"></li> |
| <li><a href="/getting-started/">Getting Started</a></li> |
| <li><a href="/security/">Security Guide</a></li> |
| <li><a href="/core-developers/">Core Developers Guide</a></li> |
| <li><a href="/tag-developers/">Tag Developers Guide</a></li> |
| <li><a href="/maven-archetypes/">Maven Archetypes</a></li> |
| <li><a href="/plugins/">Plugins</a></li> |
| <li><a href="/maven/struts2-core/apidocs/index.html">Struts Core API</a></li> |
| <li><a href="/tag-developers/tag-reference.html">Tag reference</a></li> |
| <li><a href="https://cwiki.apache.org/confluence/display/WW/FAQs">FAQs</a></li> |
| <li><a href="http://cwiki.apache.org/S2PLUGINS/home.html">Plugin registry</a></li> |
| </ul> |
| </li> |
| <li class="dropdown"> |
| <a data-toggle="dropdown" href="#" class="dropdown-toggle"> |
| Contributing<b class="caret"></b> |
| </a> |
| <ul class="dropdown-menu"> |
| <li><a href="/youatstruts.html">You at Struts</a></li> |
| <li><a href="/helping.html">How to Help FAQ</a></li> |
| <li><a href="/dev-mail.html">Development Lists</a></li> |
| <li class="divider"></li> |
| <li><a href="/submitting-patches.html">Submitting patches</a></li> |
| <li><a href="/builds.html">Source Code and Builds</a></li> |
| <li><a href="/coding-standards.html">Coding standards</a></li> |
| <li><a href="/contributors/">Contributors Guide</a></li> |
| <li class="divider"></li> |
| <li><a href="/release-guidelines.html">Release Guidelines</a></li> |
| <li><a href="/bylaws.html">PMC Charter</a></li> |
| <li><a href="/volunteers.html">Volunteers</a></li> |
| <li><a href="https://gitbox.apache.org/repos/asf?p=struts.git">Source Repository</a></li> |
| <li><a href="/updating-website.html">Updating the website</a></li> |
| </ul> |
| </li> |
| <li class="apache"><a href="http://www.apache.org/"><img src="/img/apache.png"></a></li> |
| </ul> |
| </div> |
| </div> |
| </div> |
| </nav> |
| </header> |
| |
| |
| <article class="container"> |
| <section class="col-md-12"> |
| <a class="edit-on-gh" href="https://github.com/apache/struts-site/edit/master/source/core-developers/annotations.md" title="Edit this page on GitHub">Edit on GitHub</a> |
| |
| <a href="index.html" title="back to Core Developers Guide"><< back to Core Developers Guide</a> |
| |
| <h1 class="no_toc" id="annotations">Annotations</h1> |
| |
| <ul id="markdown-toc"> |
| <li><a href="#action-annotations" id="markdown-toc-action-annotations">Action Annotations</a></li> |
| <li><a href="#workflow-annotations" id="markdown-toc-workflow-annotations">Workflow Annotations</a></li> |
| <li><a href="#interceptor-annotations" id="markdown-toc-interceptor-annotations">Interceptor Annotations</a></li> |
| <li><a href="#validation-annotations" id="markdown-toc-validation-annotations">Validation Annotations</a> <ul> |
| <li><a href="#resources" id="markdown-toc-resources">Resources</a></li> |
| </ul> |
| </li> |
| <li><a href="#type-conversion-annotations" id="markdown-toc-type-conversion-annotations">Type Conversion Annotations</a></li> |
| <li><a href="#tiles-annotations" id="markdown-toc-tiles-annotations">Tiles Annotations</a></li> |
| </ul> |
| |
| <p>In many places, applications can use Java 5 annotations as an alternative to XML and Java properties configuration. |
| This page serves as a reference for all annotations across the framework.</p> |
| |
| <h2 id="action-annotations">Action Annotations</h2> |
| |
| <p>Since Struts 2.1, these annotations are provided by the <a href="../plugins/convention/">Convention Plugin</a>. Codebehind and Zero Config |
| plugins are deprecated from Struts 2.1 on.</p> |
| |
| <p>Action annotations are available when the framework scans the classpath for Action classes, rather than specifying |
| individual mappings through XML configuration. See the <a href="../plugins/convention/">Convention Plugin</a> page for information |
| on how to set up classpath scanning to allow the use of Action annotations.</p> |
| |
| <table> |
| <thead> |
| <tr> |
| <th>Annotation</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td><a href="../plugins/convention/#action-annotation">Actions Annotation</a></td> |
| <td>Group of <code class="language-plaintext highlighter-rouge">@Action</code> annotations, maps multiple URLs to the same action</td> |
| </tr> |
| <tr> |
| <td><a href="../plugins/convention/#action-annotation">Action Annotation</a></td> |
| <td>Defines the URL of an action</td> |
| </tr> |
| <tr> |
| <td><a href="../plugins/convention/#interceptorref-annotation">InterceptorRefs Annotation</a></td> |
| <td>Group of <code class="language-plaintext highlighter-rouge">@InterceptorRef</code> annotations</td> |
| </tr> |
| <tr> |
| <td><a href="../plugins/convention/#interceptorref-annotation">InterceptorRef Annotation</a></td> |
| <td>Interceptor, or interceptor stack to be applied to at action</td> |
| </tr> |
| <tr> |
| <td><a href="../plugins/convention/#result-annotation">Results Annotation</a></td> |
| <td>Group of <code class="language-plaintext highlighter-rouge">@Result</code> annotations</td> |
| </tr> |
| <tr> |
| <td><a href="../plugins/convention/#result-annotation">Result Annotation</a></td> |
| <td>Defines a result for an action</td> |
| </tr> |
| <tr> |
| <td><a href="namespace-annotation">Namespace Annotation</a></td> |
| <td>Set the path of the action URL (used to overwrite the default)</td> |
| </tr> |
| <tr> |
| <td><a href="../plugins/convention/#resultpath-annotation">ResultPath Annotation</a></td> |
| <td>Set where the results are located (used to overwrite the default)</td> |
| </tr> |
| <tr> |
| <td><a href="..//plugins/convention/#parentpackage-annotation">ParentPackage Annotation</a></td> |
| <td>Set the parent package of the actions (used to overwrite the default)</td> |
| </tr> |
| <tr> |
| <td><a href="../plugins/convention/#exceptionmapping-annotation">ExceptionMappings</a></td> |
| <td>Group of <code class="language-plaintext highlighter-rouge">@ExceptionMapping</code> annotations</td> |
| </tr> |
| <tr> |
| <td><a href="../plugins/convention/#exceptionmapping-annotation">ExceptionMapping</a></td> |
| <td>Defines an exception mapping</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h2 id="workflow-annotations">Workflow Annotations</h2> |
| |
| <table> |
| <thead> |
| <tr> |
| <th>Annotation</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td><a href="input-config-annotation">InputConfig Annotation</a></td> |
| <td>Defines what method to execute, or result to be returned if there are validation errors</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h2 id="interceptor-annotations">Interceptor Annotations</h2> |
| |
| <p>To use these annotations, you have to specify the <a href="annotation-workflow-interceptor">AnnotationWorkflowInterceptor</a> |
| to your interceptor stack.</p> |
| |
| <table> |
| <thead> |
| <tr> |
| <th>Annotation</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td><a href="after-annotation">After Annotation</a></td> |
| <td>Marks a action method that needs to be executed after the result.</td> |
| </tr> |
| <tr> |
| <td><a href="before-annotation">Before Annotation</a></td> |
| <td>Marks a action method that needs to be executed before the main action method.</td> |
| </tr> |
| <tr> |
| <td><a href="before-result-annotation">BeforeResult Annotation</a></td> |
| <td>Marks a action method that needs to be executed before the result.</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h2 id="validation-annotations">Validation Annotations</h2> |
| |
| <p>To use annotation-based validation, annotate the class or interface with <a href="validation-annotation">Validation Annotation</a>.</p> |
| |
| <table> |
| <thead> |
| <tr> |
| <th>Annotation</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td><a href="conversion-error-field-validator-annotation">ConversionErrorFieldValidator Annotation</a></td> |
| <td>Checks if there are any conversion errors for a field.</td> |
| </tr> |
| <tr> |
| <td><a href="date-range-field-validator-annotation">DateRangeFieldValidator Annotation</a></td> |
| <td>Checks that a date field has a value within a specified range.</td> |
| </tr> |
| <tr> |
| <td><a href="double-range-field-validator-annotation">DoubleRangeFieldValidator Annotation</a></td> |
| <td>Checks that a double field has a value within a specified range.</td> |
| </tr> |
| <tr> |
| <td><a href="email-validator-annotation">EmailValidator Annotation</a></td> |
| <td>Checks that a field is a valid e-mail address.</td> |
| </tr> |
| <tr> |
| <td><a href="expression-validator-annotation">ExpressionValidator Annotation</a></td> |
| <td>Validates an expression.</td> |
| </tr> |
| <tr> |
| <td><a href="field-expression-validator-annotation">FieldExpressionValidator Annotation</a></td> |
| <td>Uses an OGNL expression to perform its validator.</td> |
| </tr> |
| <tr> |
| <td><a href="int-range-field-validator-annotation">IntRangeFieldValidator Annotation</a></td> |
| <td>Checks that a numeric field has a value within a specified range.</td> |
| </tr> |
| <tr> |
| <td><a href="regex-field-validator-annotation">RegexFieldValidator Annotation</a></td> |
| <td>Validates a regular expression for a field.</td> |
| </tr> |
| <tr> |
| <td><a href="required-field-validator-annotation">RequiredFieldValidator Annotation</a></td> |
| <td>Checks that a field is non-null.</td> |
| </tr> |
| <tr> |
| <td><a href="required-string-validator-annotation">RequiredStringValidator Annotation</a></td> |
| <td>Checks that a String field is not empty.</td> |
| </tr> |
| <tr> |
| <td><a href="string-length-field-validator-annotation">StringLengthFieldValidator Annotation</a></td> |
| <td>Checks that a String field is of the right length.</td> |
| </tr> |
| <tr> |
| <td><a href="url-validator-annotation">UrlValidator Annotation</a></td> |
| <td>Checks that a field is a valid URL.</td> |
| </tr> |
| <tr> |
| <td><a href="validation-annotation">Validation Annotation</a></td> |
| <td>Marker annotation for validation at Type level.</td> |
| </tr> |
| <tr> |
| <td><a href="validations-annotation">Validations Annotation</a></td> |
| <td>Used to group validation annotations.</td> |
| </tr> |
| <tr> |
| <td><a href="visitor-field-validator-annotation">VisitorFieldValidator Annotation</a></td> |
| <td>Invokes the validation for a property’s object type.</td> |
| </tr> |
| <tr> |
| <td><a href="custom-validator-annotation">CustomValidator Annotation</a></td> |
| <td>Use this annotation for your custom validator types.</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h3 id="resources">Resources</h3> |
| |
| <ul> |
| <li><a href="http://arsenalist.com/2007/05/10/struts-2-validation-using-annotations/">Validation using Annotations</a> (arsenalist)</li> |
| </ul> |
| |
| <h2 id="type-conversion-annotations">Type Conversion Annotations</h2> |
| |
| <p>By default, type conversion for Maps and Collections using generics is directly supported.</p> |
| |
| <p>In short, instead of specifying the types found in collections and maps as documented |
| in <a href="type-conversion">Type Conversion</a>, <strong>the collection’s generic type is used</strong>. By using annotations, |
| an application should be able to avoid using any <code class="language-plaintext highlighter-rouge">ClassName-conversion.properties</code> files.</p> |
| |
| <p>To use annotation-based type conversion, annotate the class or interface with the <a href="conversion-annotation">Conversion Annotation</a>.</p> |
| |
| <table> |
| <thead> |
| <tr> |
| <th>Annotation</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td><a href="conversion-annotation">Conversion Annotation</a></td> |
| <td>Marker annotation for type conversions at Type level.</td> |
| </tr> |
| <tr> |
| <td><a href="create-if-null-annotation">CreateIfNull Annotation</a></td> |
| <td>For Collection and Map types: Create the types within the Collection or Map, if null.</td> |
| </tr> |
| <tr> |
| <td><a href="element-annotation">Element Annotation</a></td> |
| <td>For Generic types: Specify the element type for Collection types and Map values.</td> |
| </tr> |
| <tr> |
| <td><a href="key-annotation">Key Annotation</a></td> |
| <td>For Generic types: Specify the key type for Map keys.</td> |
| </tr> |
| <tr> |
| <td><a href="key-property-annotation">KeyProperty Annotation</a></td> |
| <td>For Generic types: Specify the key property name value.</td> |
| </tr> |
| <tr> |
| <td><a href="type-conversion-annotation">TypeConversion Annotation</a></td> |
| <td>Used for class and application wide conversion rules.</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h2 id="tiles-annotations">Tiles Annotations</h2> |
| |
| <p>The <a href="../plugins/tiles/">Tiles Plugin</a> provides it’s own set of Annotations. They can be used to keep <code class="language-plaintext highlighter-rouge">tiles.xml</code> short. |
| Instead tiles definitions can be created by annotating actions.</p> |
| |
| <table> |
| <thead> |
| <tr> |
| <th>Annotation</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td>TilesDefinition</td> |
| <td>Represents a <code class="language-plaintext highlighter-rouge"><definition></code> element in tiles.xml</td> |
| </tr> |
| <tr> |
| <td>TilesDefinitions</td> |
| <td>A list of <code class="language-plaintext highlighter-rouge">TilesDefinition</code> Annotations</td> |
| </tr> |
| <tr> |
| <td>TilesPutAttribute</td> |
| <td>Represents a <code class="language-plaintext highlighter-rouge"><put-attribute></code> element in tiles.xml</td> |
| </tr> |
| <tr> |
| <td>TilesPutListAttribute</td> |
| <td>Represents a <code class="language-plaintext highlighter-rouge"><put-list-attribute></code> element in tiles.xml</td> |
| </tr> |
| <tr> |
| <td>TilesAddAttribute</td> |
| <td>Represents a <code class="language-plaintext highlighter-rouge"><add-attribute></code> element in tiles.xml</td> |
| </tr> |
| <tr> |
| <td>TilesAddListAttribute</td> |
| <td>Represents a <code class="language-plaintext highlighter-rouge"><add-list-attribute></code> element in tiles.xml</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <p> </p> |
| |
| </section> |
| </article> |
| |
| |
| <footer class="container"> |
| <div class="col-md-12"> |
| Copyright © 2000-2022 <a href="https://www.apache.org/">The Apache Software Foundation</a>. |
| Apache Struts, Struts, Apache, the Apache feather logo, and the Apache Struts project logos are |
| trademarks of The Apache Software Foundation. All Rights Reserved. |
| </div> |
| <div class="col-md-12">Logo and website design donated by <a href="https://softwaremill.com/">SoftwareMill</a>.</div> |
| </footer> |
| |
| <script>!function (d, s, id) { |
| var js, fjs = d.getElementsByTagName(s)[0]; |
| if (!d.getElementById(id)) { |
| js = d.createElement(s); |
| js.id = id; |
| js.src = "//platform.twitter.com/widgets.js"; |
| fjs.parentNode.insertBefore(js, fjs); |
| } |
| }(document, "script", "twitter-wjs");</script> |
| <script src="https://apis.google.com/js/platform.js" async="async" defer="defer"></script> |
| |
| <div id="fb-root"></div> |
| |
| <script>(function (d, s, id) { |
| var js, fjs = d.getElementsByTagName(s)[0]; |
| if (d.getElementById(id)) return; |
| js = d.createElement(s); |
| js.id = id; |
| js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1"; |
| fjs.parentNode.insertBefore(js, fjs); |
| }(document, 'script', 'facebook-jssdk'));</script> |
| |
| |
| </body> |
| </html> |