Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D24C1200497 for ; Wed, 23 Aug 2017 10:58:45 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D0D07168599; Wed, 23 Aug 2017 08:58:45 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CACB4168593 for ; Wed, 23 Aug 2017 10:58:44 +0200 (CEST) Received: (qmail 90600 invoked by uid 500); 23 Aug 2017 08:58:43 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 90579 invoked by uid 99); 23 Aug 2017 08:58:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Aug 2017 08:58:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 16D12E08BE; Wed, 23 Aug 2017 08:58:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: lukaszlenart@apache.org To: commits@struts.apache.org Date: Wed, 23 Aug 2017 08:58:42 -0000 Message-Id: <5d2836301a52449ab6297a6e08f85d66@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] struts-site git commit: Cleans up page content archived-at: Wed, 23 Aug 2017 08:58:46 -0000 Repository: struts-site Updated Branches: refs/heads/master 8479180e0 -> faa2f637c Cleans up page content Project: http://git-wip-us.apache.org/repos/asf/struts-site/repo Commit: http://git-wip-us.apache.org/repos/asf/struts-site/commit/732e451a Tree: http://git-wip-us.apache.org/repos/asf/struts-site/tree/732e451a Diff: http://git-wip-us.apache.org/repos/asf/struts-site/diff/732e451a Branch: refs/heads/master Commit: 732e451a75017d0fb0ff9fbe2d7e90c745814c33 Parents: 8479180 Author: Lukasz Lenart Authored: Wed Aug 23 10:53:21 2017 +0200 Committer: Lukasz Lenart Committed: Wed Aug 23 10:53:21 2017 +0200 ---------------------------------------------------------------------- source/core-developers/result-configuration.md | 224 +++++++------------- 1 file changed, 71 insertions(+), 153 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts-site/blob/732e451a/source/core-developers/result-configuration.md ---------------------------------------------------------------------- diff --git a/source/core-developers/result-configuration.md b/source/core-developers/result-configuration.md index 64b14bf..828503c 100644 --- a/source/core-developers/result-configuration.md +++ b/source/core-developers/result-configuration.md @@ -6,267 +6,185 @@ title: Result Configuration # Result Configuration -When an _action_ class method completes, it returns a String\. The value of the String is used to select a result element\. An action mapping will often have a set of results representing different possible outcomes\. A standard set of result tokens are defined by the - -~~~~~~~ -ActionSupport -~~~~~~~ - base class\. +When an `action` class method completes, it returns a String. The value of the String is used to select a result element. +An action mapping will often have a set of results representing different possible outcomes. A standard set of result +tokens are defined by the `ActionSupport` base class. **Predefined result names** - -~~~~~~~ +``` String SUCCESS = "success"; String NONE = "none"; String ERROR = "error"; String INPUT = "input"; String LOGIN = "login"; +``` -~~~~~~~ - -Of course, applications can define other result tokens to match specific cases\. - -(information) Returning - -~~~~~~~ -ActionSupport.NONE -~~~~~~~ - (or +Of course, applications can define other result tokens to match specific cases. -~~~~~~~ -null -~~~~~~~ -) from an _action_ class method causes the results processing to be skipped\. This is useful if the action fully handles the result processing such as writing directly to the HttpServletResponse OutputStream\. +> Returning `ActionSupport.NONE` (or `null`) from an action class method causes the results processing +> to be skipped. This is useful if the action fully handles the result processing such as writing directly +> to the HttpServletResponse OutputStream. -#####Result Elements##### +## Result Elements -The result element has two jobs\. First, it provides a logical name\. An - -~~~~~~~ -Action -~~~~~~~ - can pass back a token like "success" or "error" without knowing any other implementation details\. Second, the result element provides a result type\. Most results simply forward to a server page or template, but other [Result Types](result-types.html) can be used to do more interesting things\. +The result element has two jobs. First, it provides a logical name. An `Action` can pass back a token like `success` +or `error` without knowing any other implementation details. Second, the result element provides a result type. Most +results simply forward to a server page or template, but other [Result Types](result-types.html) can be used to do more +interesting things. __Intelligent Defaults__ -Each package may set a default result type to be used if none is specified in a result element\. If one package extends another, the "child" package can set its own default result, or inherit one from the parent\. +Each package may set a default result type to be used if none is specified in a result element. If one package extends +another, the "child" package can set its own default result, or inherit one from the parent. **Setting a default Result Type** - -~~~~~~~ +```xml - + -~~~~~~~ - -If a - -~~~~~~~ -type -~~~~~~~ - attribute is not specified, the framework will use the default - -~~~~~~~ -dispatcher -~~~~~~~ - type, which forwards to another web resource\. If the resource is a JavaServer Page, then the container will render it, using its JSP engine\. +``` -Likewise if the +If a `type` attribute is not specified, the framework will use the default `dispatcher` type, which forwards to another +web resource. If the resource is a JavaServer Page, then the container will render it, using its JSP engine. -~~~~~~~ -name -~~~~~~~ - attribute is not specified, the framework will give it the name "success"\. +Likewise if the `name` attribute is not specified, the framework will give it the name `success`. -Using these intelligent defaults, the most often used result types also become the simplest\. +Using these intelligent defaults, the most often used result types also become the simplest. **Result element without defaults** - -~~~~~~~ +```xml /ThankYou.jsp - -~~~~~~~ +``` **A Result element using some defaults** - -~~~~~~~ +```xml /ThankYou.jsp +``` -~~~~~~~ - -The - -~~~~~~~ -param -~~~~~~~ - tag sets a property on the Result object\. The most commonly\-set property is - -~~~~~~~ -location -~~~~~~~ -, which usually specifies the path to a web resources\. The - -~~~~~~~ -param -~~~~~~~ - attribute is another intelligent default\. +The `param` tag sets a property on the Result object. The most commonly-set property is `location`, which usually +specifies the path to a web resources. The `param` attribute is another intelligent default. **Result element using more defaults** - -~~~~~~~ +```xml /ThankYou.jsp +``` -~~~~~~~ - -Mixing results with intelligent defaults with other results makes it easier to see the "critical path"\. +Mixing results with intelligent defaults with other results makes it easier to see the "critical path". **Multiple Results** - -~~~~~~~ +```xml /hello/Result.jsp /hello/Error.jsp /hello/Input.jsp +``` -~~~~~~~ - -A special 'other' result can be configured by adding a result with name="\*"\. This result will only be selected if no result is found with a matching name\. - -**'\*' Other Result** +A special "other" result can be configured by adding a result with `name="*"`. This result will only be selected if no +result is found with a matching name. +**'*' Other Result** -~~~~~~~ +```xml /hello/Result.jsp /hello/Error.jsp /hello/Input.jsp /hello/Other.jsp +``` -~~~~~~~ +> The `name="*"` is **not** a wildcard pattern, it is a special name that is only selected if an exact match is not found. -(information) The name="\*" is **not** a wildcard pattern, it is a special name that is only selected if an exact match is not found\. +> In most cases if an action returns an unrecognized result name this would be a programming error and should be fixed. - (\!) In most cases if an action returns an unrecognized result name this would be a programming error and should be fixed\. - -__Multiple names__ +## Multiple names It is possible to define multiple names for the same result: - -~~~~~~~ +```xml success.jsp input-form.jsp -~~~~~~~ +``` -Such functionality was added in Struts 2\.5 +Such functionality was added in Struts 2.5 -#####Global Results##### +## Global Results -Most often, results are nested with the action element\. But some results apply to multiple actions\. In a secure application, a client might try to access a page without being authorized, and many actions may need access to a "logon" result\. +Most often, results are nested with the action element. But some results apply to multiple actions. In a secure +application, a client might try to access a page without being authorized, and many actions may need access +to a `logon` result. -If actions need to share results, a set of global results can be defined for each package\. The framework will first look for a local result nested in the action\. If a local match is not found, then the global results are checked\. +If actions need to share results, a set of global results can be defined for each package. The framework will first +look for a local result nested in the action. If a local match is not found, then the global results are checked. **Defining global results** - -~~~~~~~ +```xml /Error.jsp /Error.jsp Logon!input +``` -~~~~~~~ - -(light\-on) For more about results, see [Result Types](result-types.html). +> For more about results, see [Result Types](result-types.html). -#####Dynamic Results##### +## Dynamic Results -A result may not be known until execution time\. Consider the implementation of a state\-machine\-based execution flow; the next state might depend on any combination of form input elements, session attributes, user roles, moon phase, etc\. In other words, determining the next action, input page, etc\. may not be known at configuration time\. +A result may not be known until execution time. Consider the implementation of a state-machine-based execution flow; +the next state might depend on any combination of form input elements, session attributes, user roles, moon phase, etc. +In other words, determining the next action, input page, etc. may not be known at configuration time. -Result values may be retrieved from its corresponding Action implementation by using EL expressions that access the Action's properties, just like the Struts 2 tag libraries\. So given the following Action fragment: +Result values may be retrieved from its corresponding Action implementation by using EL expressions that access +the Action's properties, just like the Struts 2 tag libraries. So given the following Action fragment: **FragmentAction implementation** - -~~~~~~~ +```java private String nextAction; public String getNextAction() { return nextAction; } - -~~~~~~~ +``` you might define a result like this: **FragmentAction configuration** - -~~~~~~~ +```xml ${nextAction} +``` -~~~~~~~ +If a `FragmentAction` method returns `next` the actual _value_ of that result will be whatever is in `FragmentAction`'s +`nextAction` property. So `nextAction` may be computed based on whatever state information necessary then passed +at runtime to `next`'s `redirectAction`. -If a +See [Parameters in configuration results](../faq/parameters-in-configuration-results.html) for an expanded discussion.  -~~~~~~~ -FragmentAction -~~~~~~~ - method returns "next" the actual _value_ of that result will be whatever is in - -~~~~~~~ -FragmentAction -~~~~~~~ -'s - -~~~~~~~ -nextAction -~~~~~~~ - property\. So - -~~~~~~~ -nextAction -~~~~~~~ - may be computed based on whatever state information necessary then passed at runtime to "next"'s - -~~~~~~~ -redirectAction -~~~~~~~ -\. - -See _Parameters in configuration results_ for an expanded discussion\. - -  - -#####Returning Result Objects##### +## Returning Result Objects Instead of configuring results and returning the name, it is possible to return a result object: - -~~~~~~~ +```java public Result runAction() { ServletDispatcherResult result = new ServletDispatcherResult(); result.setLocation("input-form.jsp"); return result; } -~~~~~~~ - -  +```