This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/master by this push: new 3a7c35a WW-5093 - Improve tag var attribute comments. - Minor non-code changes, driven by examination of the issue. - Update taglib version from 2.3 to 2.6 - Apply missing @Override annotation to methods in several components. - ContextBean - tag attribute description updated to mention scope action. - ServletUrlRenderer - corrected code comment concerning scope of var attribute, corrected spelling mistake, changed URL case. - Set - Added JavaDoc and code comment to clarify th [...] new 8346bec Merge pull request #454 from JCgH4164838Gh792C124B5/local_WW-5093_improvement 3a7c35a is described below commit 3a7c35a014f8a3471a1b75e7546e01ecf21d5db3 Author: JCgH4164838Gh792C124B5 <43964333+jcgh4164838gh792c12...@users.noreply.github.com> AuthorDate: Sun Dec 6 22:22:27 2020 -0500 WW-5093 - Improve tag var attribute comments. - Minor non-code changes, driven by examination of the issue. - Update taglib version from 2.3 to 2.6 - Apply missing @Override annotation to methods in several components. - ContextBean - tag attribute description updated to mention scope action. - ServletUrlRenderer - corrected code comment concerning scope of var attribute, corrected spelling mistake, changed URL case. - Set - Added JavaDoc and code comment to clarify that with action scope the var is also assigned to page scope. Updated tag descriptions for var and scope to further clarify the behaviour. - Text - Added JavaDoc comment to clarify that if the var attribute is used the result is not written out, but instead saved into the action context. - AttributeMap - Whitespace cleanup in get() method, plus added @Override tags to multiple methods. --- core/pom.xml | 2 +- .../org/apache/struts2/components/ActionComponent.java | 2 ++ .../java/org/apache/struts2/components/ActionError.java | 2 ++ .../org/apache/struts2/components/ActionMessage.java | 2 ++ .../org/apache/struts2/components/ClosingUIBean.java | 1 + .../java/org/apache/struts2/components/ContextBean.java | 2 +- .../org/apache/struts2/components/GenericUIBean.java | 1 + .../java/org/apache/struts2/components/ListUIBean.java | 2 ++ .../apache/struts2/components/ServletUrlRenderer.java | 11 ++++++++--- .../src/main/java/org/apache/struts2/components/Set.java | 10 ++++++++-- .../main/java/org/apache/struts2/components/Text.java | 10 ++++++++++ .../main/java/org/apache/struts2/util/AttributeMap.java | 16 ++++++++++++++-- 12 files changed, 52 insertions(+), 9 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index f6038f6..5bb935f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -31,7 +31,7 @@ <name>Struts 2 Core</name> <properties> - <tlib.version>2.3</tlib.version> + <tlib.version>2.6</tlib.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> diff --git a/core/src/main/java/org/apache/struts2/components/ActionComponent.java b/core/src/main/java/org/apache/struts2/components/ActionComponent.java index af1ebd2..7cc3f43 100644 --- a/core/src/main/java/org/apache/struts2/components/ActionComponent.java +++ b/core/src/main/java/org/apache/struts2/components/ActionComponent.java @@ -150,10 +150,12 @@ public class ActionComponent extends ContextBean { } @Inject + @Override public void setActionMapper(ActionMapper mapper) { this.actionMapper = mapper; } + @Override public boolean end(Writer writer, String body) { boolean end = super.end(writer, "", false); try { diff --git a/core/src/main/java/org/apache/struts2/components/ActionError.java b/core/src/main/java/org/apache/struts2/components/ActionError.java index 060c3c9..5e41b54 100644 --- a/core/src/main/java/org/apache/struts2/components/ActionError.java +++ b/core/src/main/java/org/apache/struts2/components/ActionError.java @@ -61,10 +61,12 @@ public class ActionError extends UIBean { super(stack, request, response); } + @Override protected String getDefaultTemplate() { return TEMPLATE; } + @Override protected void evaluateExtraParams() { boolean isEmptyList = true; Collection<String> actionMessages = (List) findValue("actionErrors"); diff --git a/core/src/main/java/org/apache/struts2/components/ActionMessage.java b/core/src/main/java/org/apache/struts2/components/ActionMessage.java index 0f1680e..33a26cf 100644 --- a/core/src/main/java/org/apache/struts2/components/ActionMessage.java +++ b/core/src/main/java/org/apache/struts2/components/ActionMessage.java @@ -59,10 +59,12 @@ public class ActionMessage extends UIBean { super(stack, request, response); } + @Override protected String getDefaultTemplate() { return TEMPLATE; } + @Override protected void evaluateExtraParams() { boolean isEmptyList = true; Collection<String> actionMessages = (List) findValue("actionMessages"); diff --git a/core/src/main/java/org/apache/struts2/components/ClosingUIBean.java b/core/src/main/java/org/apache/struts2/components/ClosingUIBean.java index 48cccb2..c9785cf 100644 --- a/core/src/main/java/org/apache/struts2/components/ClosingUIBean.java +++ b/core/src/main/java/org/apache/struts2/components/ClosingUIBean.java @@ -46,6 +46,7 @@ public abstract class ClosingUIBean extends UIBean { this.openTemplate = openTemplate; } + @Override public boolean start(Writer writer) { boolean result = super.start(writer); try { diff --git a/core/src/main/java/org/apache/struts2/components/ContextBean.java b/core/src/main/java/org/apache/struts2/components/ContextBean.java index 8628e3a..69f393a 100644 --- a/core/src/main/java/org/apache/struts2/components/ContextBean.java +++ b/core/src/main/java/org/apache/struts2/components/ContextBean.java @@ -38,7 +38,7 @@ public abstract class ContextBean extends Component { } } - @StrutsTagAttribute(description="Name used to reference the value pushed into the Value Stack") + @StrutsTagAttribute(description="Name used to reference the value pushed into the Value Stack (scope: action).") public void setVar(String var) { if (var != null) { this.var = findString(var); diff --git a/core/src/main/java/org/apache/struts2/components/GenericUIBean.java b/core/src/main/java/org/apache/struts2/components/GenericUIBean.java index 63bb131..fbf8776 100644 --- a/core/src/main/java/org/apache/struts2/components/GenericUIBean.java +++ b/core/src/main/java/org/apache/struts2/components/GenericUIBean.java @@ -134,6 +134,7 @@ public class GenericUIBean extends UIBean { return ContainUtil.contains(obj1, obj2); } + @Override protected String getDefaultTemplate() { return TEMPLATE; } diff --git a/core/src/main/java/org/apache/struts2/components/ListUIBean.java b/core/src/main/java/org/apache/struts2/components/ListUIBean.java index ed50941..4dd23ca 100644 --- a/core/src/main/java/org/apache/struts2/components/ListUIBean.java +++ b/core/src/main/java/org/apache/struts2/components/ListUIBean.java @@ -62,6 +62,7 @@ public abstract class ListUIBean extends UIBean { super(stack, request, response); } + @Override public void evaluateExtraParams() { Object value = null; @@ -148,6 +149,7 @@ public abstract class ListUIBean extends UIBean { return ContainUtil.contains(obj1, obj2); } + @Override protected Class getValueClassType() { return null; // don't convert nameValue to anything, we need the raw value } diff --git a/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java b/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java index b8b7a3c..a302e8a 100644 --- a/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java +++ b/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java @@ -49,6 +49,7 @@ public class ServletUrlRenderer implements UrlRenderer { private ActionMapper actionMapper; private UrlHelper urlHelper; + @Override @Inject public void setActionMapper(ActionMapper mapper) { this.actionMapper = mapper; @@ -62,6 +63,7 @@ public class ServletUrlRenderer implements UrlRenderer { /** * {@inheritDoc} */ + @Override public void renderUrl(Writer writer, UrlProvider urlComponent) { String scheme = urlComponent.getHttpServletRequest().getScheme(); @@ -104,7 +106,8 @@ public class ServletUrlRenderer implements UrlRenderer { if (StringUtils.isNotEmpty(var)) { urlComponent.putInContext(result); - // add to the request and page scopes as well + // Note: Old comments stated that var was placed in the page scope, but interactive checks with EL on JSPs prove otherwise. + // Add the var attribute to the request scope as well. urlComponent.getHttpServletRequest().setAttribute(var, result); } else { try { @@ -125,6 +128,7 @@ public class ServletUrlRenderer implements UrlRenderer { /** * {@inheritDoc} */ + @Override public void renderFormUrl(Form formComponent) { String namespace = formComponent.determineNamespace(formComponent.namespace, formComponent.getStack(), formComponent.request); String action; @@ -233,6 +237,7 @@ public class ServletUrlRenderer implements UrlRenderer { } + @Override public void beforeRenderUrl(UrlProvider urlComponent) { if (urlComponent.getValue() != null) { urlComponent.setValue(urlComponent.findString(urlComponent.getValue())); @@ -298,7 +303,7 @@ public class ServletUrlRenderer implements UrlRenderer { /** * Merge request parameters into current parameters. If a parameter is - * already present, than the request parameter in the current request and value atrribute + * already present, than the request parameter in the current request and value attribute * will not override its value. * * The priority is as follows:- @@ -308,7 +313,7 @@ public class ServletUrlRenderer implements UrlRenderer { * <li>parameter from the param tag (most priority)</li> * </ul> * - * @param value the value attribute (url to be generated by this component) + * @param value the value attribute (URL to be generated by this component) * @param parameters component parameters * @param contextParameters request parameters */ diff --git a/core/src/main/java/org/apache/struts2/components/Set.java b/core/src/main/java/org/apache/struts2/components/Set.java index ff1a27c..8cb1ca4 100644 --- a/core/src/main/java/org/apache/struts2/components/Set.java +++ b/core/src/main/java/org/apache/struts2/components/Set.java @@ -60,6 +60,8 @@ import com.opensymphony.xwork2.util.ValueStack; * * <li>scope (String): The scope in which to assign the variable. Can be <b>application</b>, <b>session</b>, * <b>request</b>, <b>page</b>, or <b>action</b>. By default it is <b>action</b>.</li> + * + * <li>Note: With the <b>action</b> scope, the variable is <em>also</em> assigned to the <b>page</b> scope. * * </ul> * @@ -88,6 +90,7 @@ public class Set extends ContextBean { super(stack); } + @Override public boolean end(Writer writer, String body) { ValueStack stack = getStack(); @@ -113,6 +116,7 @@ public class Set extends ContextBean { } else if ("page".equalsIgnoreCase(scope)) { stack.setValue("#attr['" + getVar() + "']", o, false); } else { + // Default scope is action. Note: The action acope handling also adds the var to the page scope. stack.getContext().put(getVar(), o); stack.setValue("#attr['" + getVar() + "']", o, false); } @@ -120,13 +124,15 @@ public class Set extends ContextBean { return super.end(writer, body); } - @StrutsTagAttribute(required=true, description="Name used to reference the value pushed into the Value Stack") + @StrutsTagAttribute(required=true, description="Name used to reference the value pushed into the Value Stack (default scope: action," + + "<em>override</em> with the scope attribute).") + @Override public void setVar(String var) { super.setVar(var); } @StrutsTagAttribute(description="The scope in which to assign the variable. Can be <b>application</b>" + - ", <b>session</b>, <b>request</b>, <b>page</b>, or <b>action</b>.", defaultValue="action") + ", <b>session</b>, <b>request</b>, <b>page</b>, or <b>action</b> (action scope <em>also</em> adds it to the page scope).", defaultValue="action") public void setScope(String scope) { this.scope = scope; } diff --git a/core/src/main/java/org/apache/struts2/components/Text.java b/core/src/main/java/org/apache/struts2/components/Text.java index 9f59e09..38cde39 100644 --- a/core/src/main/java/org/apache/struts2/components/Text.java +++ b/core/src/main/java/org/apache/struts2/components/Text.java @@ -52,6 +52,12 @@ import java.util.List; * tag will be used as default message. If no value is found, the key of the * message will not be written out. * </p> + * + * <p> + * Note: If the <b>var</b> attribute is used with this tag, the tag's value will + * <em>not</em> be written out. Instead the result will be saved into the + * action context (action scope). + * </p> * <!-- END SNIPPET: javadoc --> * * <!-- START SNIPPET: params --> @@ -156,6 +162,7 @@ public class Text extends ContextBean implements Param.UnnamedParametric { this.escapeCsv = escapeCsv; } + @Override public boolean usesBody() { // overriding this to true such that EVAL_BODY_BUFFERED is return and // bodyContent will be valid hence, text between start & end tag will @@ -163,6 +170,7 @@ public class Text extends ContextBean implements Param.UnnamedParametric { return true; } + @Override public boolean end(Writer writer, String body) { actualName = findString(name, "name", "You must specify the i18n key. Example: welcome.header"); String defaultMessage; @@ -189,10 +197,12 @@ public class Text extends ContextBean implements Param.UnnamedParametric { return super.end(writer, ""); } + @Override public void addParameter(String key, Object value) { addParameter(value); } + @Override public void addParameter(Object value) { if (values.isEmpty()) { values = new ArrayList<>(4); diff --git a/core/src/main/java/org/apache/struts2/util/AttributeMap.java b/core/src/main/java/org/apache/struts2/util/AttributeMap.java index a6eebb4..ea088b4 100644 --- a/core/src/main/java/org/apache/struts2/util/AttributeMap.java +++ b/core/src/main/java/org/apache/struts2/util/AttributeMap.java @@ -52,26 +52,32 @@ public class AttributeMap implements Map { this.context = context; } + @Override public boolean isEmpty() { throw new UnsupportedOperationException(UNSUPPORTED); } + @Override public void clear() { throw new UnsupportedOperationException(UNSUPPORTED); } + @Override public boolean containsKey(Object key) { return (get(key) != null); } + @Override public boolean containsValue(Object value) { throw new UnsupportedOperationException(UNSUPPORTED); } + @Override public Set entrySet() { return Collections.EMPTY_SET; } + @Override public Object get(Object key) { PageContext pc = getPageContext(); @@ -88,9 +94,9 @@ public class AttributeMap implements Map { return application.get(key); } } else { - try{ + try { return pc.findAttribute(key.toString()); - }catch (NullPointerException npe){ + } catch (NullPointerException npe) { return null; } } @@ -98,10 +104,12 @@ public class AttributeMap implements Map { return null; } + @Override public Set keySet() { return Collections.EMPTY_SET; } + @Override public Object put(Object key, Object value) { PageContext pc = getPageContext(); if (pc != null) { @@ -111,18 +119,22 @@ public class AttributeMap implements Map { return null; } + @Override public void putAll(Map t) { throw new UnsupportedOperationException(UNSUPPORTED); } + @Override public Object remove(Object key) { throw new UnsupportedOperationException(UNSUPPORTED); } + @Override public int size() { throw new UnsupportedOperationException(UNSUPPORTED); } + @Override public Collection values() { return Collections.EMPTY_SET; }