This is an automated email from the ASF dual-hosted git repository. git-site-role pushed a commit to branch asf-site in repository https://gitbox.apache.org/repos/asf/struts-site.git
The following commit(s) were added to refs/heads/asf-site by this push: new 9f9c057 Automatic Site Publish by Buildbot 9f9c057 is described below commit 9f9c05707d39d4323514ab29c03ba8d11dc0fcc1 Author: buildbot <us...@infra.apache.org> AuthorDate: Thu Nov 5 12:34:49 2020 +0000 Automatic Site Publish by Buildbot --- .../{result-types.html => plain-result.html} | 149 ++++----------------- output/core-developers/result-types.html | 6 +- 2 files changed, 31 insertions(+), 124 deletions(-) diff --git a/output/core-developers/result-types.html b/output/core-developers/plain-result.html similarity index 54% copy from output/core-developers/result-types.html copy to output/core-developers/plain-result.html index da3605c..f563f6c 100644 --- a/output/core-developers/result-types.html +++ b/output/core-developers/plain-result.html @@ -7,7 +7,7 @@ <meta http-equiv="Content-Language" content="en"/> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> - <title>Result Types</title> + <title>Plain Result</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"> @@ -127,140 +127,43 @@ <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/plain-result.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> - <a class="edit-on-gh" href="https://github.com/apache/struts-site/edit/master/source/core-developers/result-types.md" title="Edit this page on GitHub">Edit on GitHub</a> - <h1 id="result-types">Result Types</h1> + + <h1 id="plain-result">Plain Result</h1> -<p>Most use cases can be divided into two phases. First, we need to change or query the application’s state, and then we need -to present an updated view of the application. The Action class manages the application’s state, and the Result Type -manages the view.</p> +<h2 id="description">Description</h2> -<h2 id="predefined-result-types">Predefined Result Types</h2> +<p>You create this result programmatically in an action and return it as a result of the action. No result definition +is needed in <code class="highlighter-rouge">struts.xml</code>. See the examples below how to use it. Please notice that the method result type is <code class="highlighter-rouge">PlainResult</code> +instead of <code class="highlighter-rouge">String</code>. Please explore the API for more methods - if any is missing you can either extends the interface +or report it in <a href="https://issues.apache.org/jira/projects/WW/">JIRA</a>.</p> -<p>The framework provides several implementations of the <code class="highlighter-rouge">com.opensymphony.xwork2.Result</code> interface, ready to use in your -own applications.</p> +<blockquote> + <p>NOTE: This result is available since Struts 2.6 and it requires Java 8</p> +</blockquote> -<table> - <tbody> - <tr> - <td><a href="chain-result.html">Chain Result</a></td> - <td>Used for <a href="action-chaining.html">Action Chaining</a></td> - </tr> - <tr> - <td><a href="dispatcher-result.html">Dispatcher Result</a></td> - <td>Used for web resource integration, including <em>JSP</em> integration</td> - </tr> - <tr> - <td><a href="freemarker-result.html">FreeMarker Result</a></td> - <td>Used for <em>FreeMarker</em> integration</td> - </tr> - <tr> - <td><a href="httpheader-result.html">HttpHeader Result</a></td> - <td>Used to control special HTTP behaviors</td> - </tr> - <tr> - <td><a href="redirect-result.html">Redirect Result</a></td> - <td>Used to redirect to another URL (web resource)</td> - </tr> - <tr> - <td><a href="redirect-action-result.html">Redirect Action Result</a></td> - <td>Used to redirect to another action mapping</td> - </tr> - <tr> - <td><a href="stream-result.html">Stream Result</a></td> - <td>Used to stream an InputStream back to the browser (usually for file downloads)</td> - </tr> - <tr> - <td><a href="velocity-result.html">Velocity Result</a></td> - <td>Used for <em>Velocity</em> integration</td> - </tr> - <tr> - <td><a href="xsl-result.html">XSL Result</a></td> - <td>Used for XML/XSLT integration</td> - </tr> - <tr> - <td><a href="plaintext-result.html">PlainText Result</a></td> - <td>Used to display the raw content of a particular page (i.e jsp, HTML)</td> - </tr> - <tr> - <td><a href="../plugins/tiles/">Tiles Result</a></td> - <td>Used to provide Tiles integration</td> - </tr> - <tr> - <td><a href="../plugins/tiles-3/">Tiles 3 Result</a></td> - <td>Used to provide Tiles 3 integration</td> - </tr> - <tr> - <td><a href="postback-result.html">Postback Result</a></td> - <td>Used to postback request parameters as a form to the specified destination</td> - </tr> - <tr> - <td><a href="../plugins/json/">JSON Result</a></td> - <td>Used to serialize actions into JSON</td> - </tr> - </tbody> -</table> +<h2 id="parameters">Parameters</h2> -<h2 id="optional">Optional</h2> +<p>no parameters</p> -<table> - <tbody> - <tr> - <td><a href="../plugins/jasperreports/">JasperReports Plugin</a></td> - <td>Used for <a href="../getting-started/jasper-reports-tutorial.html">JasperReports Tutorial</a> integration</td> - <td>Optional, third-party plugin</td> - </tr> - </tbody> -</table> +<h2 id="examples">Examples</h2> -<p>Additional Result Types can be created and plugged into an application by implementing the <code class="highlighter-rouge">com.opensymphony.xwork2.Result</code> -interface. Custom Result Types might include generating an email or JMS message, generating images, and so forth.</p> +<pre><code class="language-Java">public class UserAction { -<h2 id="default-parameters">Default Parameters</h2> + private String id; -<p>To minimize configuration, Results can be configured with a single value, which will be converted into a parameter, -and each Result can specify which parameter this value should be set as. For example, here is a result defined in XML -that uses a default parameter:</p> + public PlainResult execute() { + return response -> response.write("User Id: " + id); + } -<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><result</span> <span class="na">type=</span><span class="s">"freemarker"</span><span class="nt">></span>foo.fm<span class="nt"></result></span> -</code></pre></div></div> + public PlainResult html() { + return response -> response.write("<b>test</b>").withContentTypeTextHtml(); + } -<p>That is the equivalent to this:</p> - -<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt"><result</span> <span class="na">type=</span><span class="s">"freemarker"</span><span class="nt">></span> - <span class="nt"><param</span> <span class="na">name=</span><span class="s">"location"</span><span class="nt">></span>foo.vm<span class="nt"></param></span> -<span class="nt"></result></span> -</code></pre></div></div> - -<p>Since probably 95% of your actions won’t need results that contain multiple parameters, this little shortcut saves you -a significant amount of configuration. It also follows that if you have specified the default parameter, you don’t need -to set the same parameter as a specifically-named parameter.</p> - -<h2 id="registering-result-types">Registering Result Types</h2> - -<p>All Result Types are plugged in via the <a href="result-configuration.html">Result Configuration</a>.</p> - -<h2 id="extending">Extending</h2> - -<p>You can always extend defined result types and implement whatever logic you need. To simplify process of that, you can -define your custom <code class="highlighter-rouge">ResultFactory</code> and use it with connection with custom interface which your Result implements. -Check <a href="object-factory.html">Define dedicated factory</a> to see how to do it.</p> - -<p>Struts 2 provides one such extension for you:</p> - -<p><code class="highlighter-rouge">ParamNameAwareResult</code> interface when used with <code class="highlighter-rouge">StrutsResultBuilder</code> can limit parameters assigned to the result. -So you can simple extend existing result with such a functionality as below:</p> - -<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyResult</span> <span class="kd">extends</span> <span class="n">ServletDispatcherResult</span> <span class="kd">implements</span> <span class="n">ParamNameAwareResult</span> <span class="o">{</span> - - <span class="kd">public</span> <span class="kt">boolean</span> <span class="nf">acceptableParamName</span><span class="o">(</span><span class="n">String</span> <span class="n">name</span><span class="o">,</span> <span class="n">String</span> <span class="n">value</span><span class="o">)</span> <span class="o">{</span> - <span class="k">return</span> <span class="s">"accept"</span><span class="o">.</span><span class="na">equals</span><span class="o">(</span><span class="n">name</span><span class="o">);</span> - <span class="o">}</span> - -<span class="o">}</span> -</code></pre></div></div> - -<p>and then register it and use instead of default <code class="highlighter-rouge">dispatcher</code> result.</p> +} +</code></pre> </section> </article> diff --git a/output/core-developers/result-types.html b/output/core-developers/result-types.html index da3605c..af6dd95 100644 --- a/output/core-developers/result-types.html +++ b/output/core-developers/result-types.html @@ -179,8 +179,12 @@ own applications.</p> <td>Used for XML/XSLT integration</td> </tr> <tr> + <td><a href="plain-result">Plain Result</a></td> + <td>A plain result which all you to write directly to a HttpResponse using a simplified API (since Struts 2.6)</td> + </tr> + <tr> <td><a href="plaintext-result.html">PlainText Result</a></td> - <td>Used to display the raw content of a particular page (i.e jsp, HTML)</td> + <td>Used to display the raw content of a particular file/page (i.e jsp, HTML)</td> </tr> <tr> <td><a href="../plugins/tiles/">Tiles Result</a></td>