From b1e9eae01ca9a33f597a952fd9944f01c68f0f66 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Wed, 9 Feb 2022 17:33:46 +0100 Subject: [PATCH 1/4] WW-5168 Support submit unchecked in Javatemplates and fixes logic for all FTL template --- .../apache/struts2/components/Checkbox.java | 3 +- .../views/java/simple/CheckboxHandler.java | 39 +++++++++++-------- .../views/java/simple/CheckboxTest.java | 19 +++++++++ 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/components/Checkbox.java b/core/src/main/java/org/apache/struts2/components/Checkbox.java index 591f425ac2..dd853caba1 100644 --- a/core/src/main/java/org/apache/struts2/components/Checkbox.java +++ b/core/src/main/java/org/apache/struts2/components/Checkbox.java @@ -75,7 +75,8 @@ protected void evaluateExtraParams() { } if (submitUnchecked != null) { - addParameter("submitUnchecked", findValue(submitUnchecked, Boolean.class)); + Object parsedValue = findValue(submitUnchecked, Boolean.class); + addParameter("submitUnchecked", parsedValue == null ? Boolean.valueOf(submitUnchecked) : parsedValue); } else { addParameter("submitUnchecked", false); } diff --git a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/CheckboxHandler.java b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/CheckboxHandler.java index c712ddaeb6..6f0e9651bb 100644 --- a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/CheckboxHandler.java +++ b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/CheckboxHandler.java @@ -18,13 +18,14 @@ */ package org.apache.struts2.views.java.simple; -import org.apache.struts2.views.java.Attributes; -import org.apache.struts2.views.java.TagGenerator; import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.StringEscapeUtils; +import org.apache.struts2.views.java.Attributes; +import org.apache.struts2.views.java.TagGenerator; import java.io.IOException; import java.util.Map; +import java.util.Objects; public class CheckboxHandler extends AbstractTagHandler implements TagGenerator { public void generate() throws IOException { @@ -35,29 +36,33 @@ public void generate() throws IOException { String id = (String) params.get("id"); String name = (String) params.get("name"); Object disabled = params.get("disabled"); + boolean submitUnchecked = Boolean.parseBoolean(Objects.toString(params.get("submitUnchecked"), "false")); attrs.add("type", "checkbox") - .add("name", name) - .add("value", fieldValue) - .addIfTrue("checked", params.get("nameValue")) - .addIfTrue("readonly", params.get("readonly")) - .addIfTrue("disabled", disabled) - .addIfExists("tabindex", params.get("tabindex")) - .addIfExists("id", id) - .addIfExists("class", params.get("cssClass")) - .addIfExists("style", params.get("cssStyle")) - .addIfExists("title", params.get("title")); + .add("name", name) + .add("value", fieldValue) + .addIfTrue("checked", params.get("nameValue")) + .addIfTrue("readonly", params.get("readonly")) + .addIfTrue("disabled", disabled) + .addIfExists("tabindex", params.get("tabindex")) + .addIfExists("id", id) + .addIfExists("class", params.get("cssClass")) + .addIfExists("style", params.get("cssStyle")) + .addIfExists("title", params.get("title")); start("input", attrs); end("input"); - //hidden input - attrs = new Attributes(); - attrs.add("type", "hidden") + if (!submitUnchecked) { + //hidden input + attrs = new Attributes(); + + attrs.add("type", "hidden") .add("id", "__checkbox_" + StringUtils.defaultString(StringEscapeUtils.escapeHtml4(id))) .add("name", "__checkbox_" + StringUtils.defaultString(StringEscapeUtils.escapeHtml4(name))) .add("value", "__checkbox_" + StringUtils.defaultString(StringEscapeUtils.escapeHtml4(fieldValue))) .addIfTrue("disabled", disabled); - start("input", attrs); - end("input"); + start("input", attrs); + end("input"); + } } } diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java index 10a8e36c2f..fa7d53a048 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java @@ -45,6 +45,25 @@ public void testRenderCheckbox() { assertEquals(expected, output); } + public void testRenderUncheckCheckbox() { + tag.setName("name_"); + tag.setDisabled("true"); + tag.setTabindex("1"); + tag.setId("id_"); + tag.setCssClass("class"); + tag.setCssStyle("style"); + tag.setTitle("title"); + tag.setFieldValue("xyz"); + tag.setSubmitUnchecked("true"); + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + String output = writer.getBuffer().toString(); + String expected = s(""); + assertEquals(expected, output); + } + public void testRenderCheckboxWithNameValue() { tag.setName("name_"); tag.setValue("%{someValue}"); From 1c3cab2e6f78f0479b4e776080693ec7faa149c6 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Thu, 10 Feb 2022 18:42:10 +0100 Subject: [PATCH 2/4] WW-5168 Fixes disabled attribute across all the Javatemplate tags --- .../apache/struts2/components/Component.java | 5 +- .../org/apache/struts2/components/UIBean.java | 12 ++-- .../apache/struts2/views/java/Attributes.java | 14 ++-- .../views/java/simple/AnchorHandler.java | 14 ++-- .../views/java/simple/LinkHandler.java | 6 +- .../views/java/simple/ResetHandler.java | 17 ++--- .../struts2/views/java/simple/AnchorTest.java | 2 +- .../views/java/simple/CheckboxTest.java | 5 +- .../struts2/views/java/simple/FileTest.java | 2 +- .../struts2/views/java/simple/HiddenTest.java | 2 +- .../struts2/views/java/simple/LinkTest.java | 65 ++++++++++++++----- .../views/java/simple/PasswordTest.java | 8 +-- .../struts2/views/java/simple/SelectTest.java | 2 +- .../struts2/views/java/simple/SubmitTest.java | 8 +-- .../views/java/simple/TextAreaTest.java | 4 +- .../views/java/simple/TextFieldTest.java | 2 +- 16 files changed, 104 insertions(+), 64 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/components/Component.java b/core/src/main/java/org/apache/struts2/components/Component.java index 2b0c58a3b6..f45dac07d6 100644 --- a/core/src/main/java/org/apache/struts2/components/Component.java +++ b/core/src/main/java/org/apache/struts2/components/Component.java @@ -384,9 +384,8 @@ protected Object findValue(String expression, Class toType) { return expression; } } else { - expression = stripExpression(expression); - - return getStack().findValue(expression, toType, throwExceptionOnELFailure); + String strippedExpression = stripExpression(expression); + return getStack().findValue(strippedExpression, toType, throwExceptionOnELFailure); } } diff --git a/core/src/main/java/org/apache/struts2/components/UIBean.java b/core/src/main/java/org/apache/struts2/components/UIBean.java index 85b3d1bb9e..4a4b5eb2b2 100644 --- a/core/src/main/java/org/apache/struts2/components/UIBean.java +++ b/core/src/main/java/org/apache/struts2/components/UIBean.java @@ -702,11 +702,13 @@ public void evaluateParams() { } if (requiredLabel != null) { - addParameter("required", findValue(requiredLabel, Boolean.class)); + Object parsedValue = findValue(requiredLabel, Boolean.class); + addParameter("required", parsedValue == null ? Boolean.valueOf(requiredLabel) : parsedValue); } if (disabled != null) { - addParameter("disabled", findValue(disabled, Boolean.class)); + Object parsedValue = findValue(disabled, Boolean.class); + addParameter("disabled", parsedValue == null ? Boolean.valueOf(disabled) : parsedValue); } if (tabindex != null) { @@ -886,9 +888,9 @@ public void evaluateParams() { this.addParameter("tooltipDelay", findString(this.tooltipDelay)); if (this.javascriptTooltip != null) { - Boolean jsTooltips = (Boolean) findValue(this.javascriptTooltip, Boolean.class); + Object jsTooltips = findValue(this.javascriptTooltip, Boolean.class); //TODO use a Boolean model when tooltipConfig is dropped - this.addParameter("jsTooltipEnabled", jsTooltips.toString()); + this.addParameter("jsTooltipEnabled", jsTooltips == null ? this.javascriptTooltip : jsTooltips.toString()); if (form != null) form.addParameter("hasTooltip", jsTooltips); @@ -968,7 +970,7 @@ protected Map getTooltipConfig(UIBean component) { // 1] UI component's tooltipConfig attribute OR // 2] param tag value attribute - result = new LinkedHashMap<>((Map) tooltipConfigObj); + result = new LinkedHashMap((Map) tooltipConfigObj); } else if (tooltipConfigObj instanceof String) { // we get this if its configured using diff --git a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/Attributes.java b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/Attributes.java index 3a6050702a..77a51e64c0 100644 --- a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/Attributes.java +++ b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/Attributes.java @@ -28,7 +28,7 @@ */ public class Attributes extends LinkedHashMap { - private static final long serialVersionUID = 4103241472140545630L; + private static final long serialVersionUID = 4103241472140545630L; public Attributes add(String key, String value) { return add(key, value, true); @@ -74,15 +74,17 @@ public Attributes addIfExists(String attrName, Object paramValue, boolean encode * @return this */ public Attributes addIfTrue(String attrName, Object paramValue) { - if (paramValue != null) { - if ((paramValue instanceof Boolean && ((Boolean) paramValue).booleanValue()) || - (Boolean.valueOf(paramValue.toString()).booleanValue())) { - put(attrName, attrName); - } + if (paramValue != null && isTrue(paramValue)) { + put(attrName, attrName); } return this; } + private boolean isTrue(Object paramValue) { + return (paramValue instanceof Boolean && (Boolean) paramValue) + || (Boolean.parseBoolean(paramValue.toString())); + } + /** * Add a key/value pair to the attributes, if the value is null, it will be set as an empty string. * Value is html encoded. diff --git a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/AnchorHandler.java b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/AnchorHandler.java index 405088f0c5..510abb6913 100644 --- a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/AnchorHandler.java +++ b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/AnchorHandler.java @@ -37,12 +37,14 @@ public void generate() throws IOException { Attributes attrs = new Attributes(); attrs.addIfExists("name", params.get("name")) - .addIfExists("id", params.get("id")) - .addIfExists("class", params.get("cssClass")) - .addIfExists("style", params.get("cssStyle")) - .addIfExists("href", params.get("href"), false) - .addIfExists("title", params.get("title")) - .addIfExists("tabindex", params.get("tabindex")); + .addIfExists("id", params.get("id")) + .addIfExists("class", params.get("cssClass")) + .addIfExists("style", params.get("cssStyle")) + .addIfExists("href", params.get("href"), false) + .addIfTrue("disabled", params.get("disabled")) + .addIfExists("title", params.get("title")) + .addIfExists("tabindex", params.get("tabindex")); + start("a", attrs); String body = (String) params.get("body"); Boolean escapeHtmlBody = (Boolean) params.get("escapeHtmlBody"); diff --git a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/LinkHandler.java b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/LinkHandler.java index 55a7d353e5..cf2daeec44 100644 --- a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/LinkHandler.java +++ b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/LinkHandler.java @@ -40,9 +40,13 @@ public void generate() throws IOException { .addIfExists("referrerpolicy", params.get("referrerpolicy")) .addIfExists("type", params.get("type")) .addIfExists("as", params.get("as")) - .addIfExists("disabled", params.get("disabled")) .addIfExists("title", params.get("title")); + // see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-disabled + if ("stylesheet".equals(params.get("rel"))) { + attrs.addIfTrue("disabled", params.get("disabled")); + } + start("link", attrs); end("link"); } diff --git a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.java b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.java index c0eb9aa7a3..fbb2dce09e 100644 --- a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.java +++ b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/ResetHandler.java @@ -18,9 +18,9 @@ */ package org.apache.struts2.views.java.simple; -import org.apache.struts2.views.java.TagGenerator; -import org.apache.struts2.views.java.Attributes; import org.apache.commons.lang3.StringUtils; +import org.apache.struts2.views.java.Attributes; +import org.apache.struts2.views.java.TagGenerator; import java.io.IOException; import java.util.Map; @@ -34,12 +34,13 @@ public void generate() throws IOException { boolean isButton = "button".equals(params.get("type")); attrs.addDefaultToEmpty("name", params.get("name")) - .add("type", "reset") - .addIfExists("value", params.get("nameValue")) - .addIfExists("tabindex", params.get("tabindex")) - .addIfExists("id", params.get("id")) - .addIfExists("class", params.get("cssClass")) - .addIfExists("style", params.get("cssStyle")); + .add("type", "reset") + .addIfExists("value", params.get("nameValue")) + .addIfTrue("disabled", params.get("disabled")) + .addIfExists("tabindex", params.get("tabindex")) + .addIfExists("id", params.get("id")) + .addIfExists("class", params.get("cssClass")) + .addIfExists("style", params.get("cssStyle")); if (!isButton) attrs.addIfExists("title", params.get("title")); diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AnchorTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AnchorTest.java index 58709a245a..5957135478 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AnchorTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/AnchorTest.java @@ -43,7 +43,7 @@ public void testRenderAnchor() { theme.renderTag(getTagName(), context); theme.renderTag(getTagName() + "-close", context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java index fa7d53a048..8bb915d89c 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java @@ -29,7 +29,7 @@ public class CheckboxTest extends AbstractCommonAttributesTest { public void testRenderCheckbox() { tag.setName("name_"); - tag.setDisabled("true"); + tag.setDisabled("false"); tag.setTabindex("1"); tag.setId("id_"); tag.setCssClass("class"); @@ -60,14 +60,13 @@ public void testRenderUncheckCheckbox() { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } public void testRenderCheckboxWithNameValue() { tag.setName("name_"); tag.setValue("%{someValue}"); - tag.setDisabled("true"); tag.evaluateParams(); map.putAll(tag.getParameters()); diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/FileTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/FileTest.java index 3334fd3c78..0a455c28a6 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/FileTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/FileTest.java @@ -43,7 +43,7 @@ public void testRenderTextField() { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/HiddenTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/HiddenTest.java index 48c5dc3ef3..497ea88f14 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/HiddenTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/HiddenTest.java @@ -41,7 +41,7 @@ public void testRenderHidden() { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/LinkTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/LinkTest.java index 8e7b039359..873ede2696 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/LinkTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/LinkTest.java @@ -31,7 +31,7 @@ public class LinkTest extends AbstractTest{ private static final String NONCE_VAL = "r4andom"; - public void testRenderScriptTag() { + public void testRenderLinkTag() { tag.setHref("testhref"); tag.setHreflang("test"); tag.setRel("module"); @@ -41,27 +41,60 @@ public void testRenderScriptTag() { tag.setCrossorigin("same-origin"); tag.setType("anonymous"); tag.setAs("test"); - tag.setDisabled("disabled_"); + tag.setDisabled("true"); tag.setTitle("test"); tag.evaluateParams(); map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); - String s = writer.getBuffer().toString(); - - assertTrue("Incorrect href attribute for link tag", s.contains("href=\"testhref\"")); - assertTrue("Incorrect hreflang attribute for link tag", s.contains("hreflang=\"test\"")); - assertTrue("Incorrect rel attribute for link tag", s.contains("rel=\"module\"")); - assertTrue("Incorrect media attribute for link tag", s.contains("media=\"foo\"")); - assertTrue("Incorrect referrerpolicy attribute for link tag", s.contains("referrerpolicy=\"test\"")); - assertTrue("Incorrect sizes attribute for link tag", s.contains("sizes=\"foo\"")); - assertTrue("Incorrect crossorigin attribute for link tag", s.contains("crossorigin=\"same-origin\"")); - assertTrue("Incorrect type attribute for link tag", s.contains("type=\"anonymous\"")); - assertTrue("Incorrect as attribute for link tag", s.contains("as=\"test\"")); - assertTrue("Non-existent disabled attribute for link tag", s.contains("disabled=\"disabled_\"")); - assertTrue("Incorrect title attribute for link tag", s.contains("title=\"test\"")); - assertTrue("Incorrect nonce attribute for link tag", s.contains("nonce=\"" + NONCE_VAL+"\"")); + String output = writer.getBuffer().toString(); + + assertTrue("Incorrect href attribute for link tag", output.contains(s("href='testhref'"))); + assertTrue("Incorrect hreflang attribute for link tag", output.contains(s("hreflang='test'"))); + assertTrue("Incorrect rel attribute for link tag", output.contains(s("rel='module'"))); + assertTrue("Incorrect media attribute for link tag", output.contains(s("media='foo'"))); + assertTrue("Incorrect referrerpolicy attribute for link tag", output.contains(s("referrerpolicy='test'"))); + assertTrue("Incorrect sizes attribute for link tag", output.contains(s("sizes='foo'"))); + assertTrue("Incorrect crossorigin attribute for link tag", output.contains(s("crossorigin='same-origin'"))); + assertTrue("Incorrect type attribute for link tag", output.contains(s("type='anonymous'"))); + assertTrue("Incorrect as attribute for link tag", output.contains(s("as='test'"))); + assertFalse("Non-existent disabled attribute for link tag", output.contains(s("disabled='disabled'"))); + assertTrue("Incorrect title attribute for link tag", output.contains(s("title='test'"))); + assertTrue("Incorrect nonce attribute for link tag", output.contains(s("nonce='" + NONCE_VAL+"'"))); + } + + public void testRenderLinkTagAsStylesheet() { + tag.setHref("testhref"); + tag.setHreflang("test"); + tag.setRel("stylesheet"); + tag.setMedia("foo"); + tag.setReferrerpolicy("test"); + tag.setSizes("foo"); + tag.setCrossorigin("same-origin"); + tag.setType("anonymous"); + tag.setAs("test"); + tag.setDisabled("true"); + tag.setTitle("test"); + + tag.evaluateParams(); + map.putAll(tag.getParameters()); + theme.renderTag(getTagName(), context); + String output = writer.getBuffer().toString(); + + assertTrue("Incorrect href attribute for link tag", output.contains(s("href='testhref'"))); + assertTrue("Incorrect hreflang attribute for link tag", output.contains(s("hreflang='test'"))); + assertTrue("Incorrect rel attribute for link tag", output.contains(s("rel='stylesheet'"))); + assertTrue("Incorrect media attribute for link tag", output.contains(s("media='foo'"))); + assertTrue("Incorrect referrerpolicy attribute for link tag", output.contains(s("referrerpolicy='test'"))); + assertTrue("Incorrect sizes attribute for link tag", output.contains(s("sizes='foo'"))); + assertTrue("Incorrect crossorigin attribute for link tag", output.contains(s("crossorigin='same-origin'"))); + assertTrue("Incorrect type attribute for link tag", output.contains(s("type='anonymous'"))); + assertTrue("Incorrect as attribute for link tag", output.contains(s("as='test'"))); + assertTrue("Incorrect disabled attribute for link tag", output.contains(s("disabled='disabled'"))); + assertTrue("Incorrect title attribute for link tag", output.contains(s("title='test'"))); + assertTrue("Incorrect nonce attribute for link tag", output.contains(s("nonce='" + NONCE_VAL+"'"))); } + @Override protected UIBean getUIBean() throws Exception { return tag; diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/PasswordTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/PasswordTest.java index da26301b49..84f48ce92d 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/PasswordTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/PasswordTest.java @@ -24,11 +24,10 @@ import org.apache.struts2.components.UIBean; public class PasswordTest extends AbstractCommonAttributesTest { + private Password tag; - private boolean showPassword; public void testRenderPassword() throws Exception { - this.showPassword = false; super.setUp(); this.tag = new Password(stack, request, response); @@ -47,12 +46,11 @@ public void testRenderPassword() throws Exception { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } public void testRenderPasswordShowIt() throws Exception { - this.showPassword = true; super.setUp(); this.tag = new Password(stack, request, response); @@ -71,7 +69,7 @@ public void testRenderPasswordShowIt() throws Exception { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/SelectTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/SelectTest.java index bfe7e03609..28d601fb67 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/SelectTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/SelectTest.java @@ -45,7 +45,7 @@ public void testRenderSelect() { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java index 8609630a7a..cbb7f6c5f4 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/SubmitTest.java @@ -47,7 +47,7 @@ public void testRenderButtonWithBody() { map.putAll(tag.getParameters()); theme.renderTag(getTagName() + "-close", context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } @@ -69,7 +69,7 @@ public void testRenderButtonWithLabel() { theme.renderTag(getTagName(), context); theme.renderTag(getTagName() + "-close", context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } @@ -91,7 +91,7 @@ public void testRenderButtonSubmit() { theme.renderTag(getTagName(), context); theme.renderTag(getTagName() + "-close", context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } @@ -112,7 +112,7 @@ public void testRenderButtonWithoutType() { theme.renderTag(getTagName(), context); theme.renderTag(getTagName() + "-close", context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java index bae57795e1..fb5d8e0719 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/TextAreaTest.java @@ -44,7 +44,7 @@ public void testRenderTextArea() { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } @@ -63,7 +63,7 @@ public void testRenderTextAreaDefaults() { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/TextFieldTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/TextFieldTest.java index 7371fa1b44..5973ea5fff 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/TextFieldTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/TextFieldTest.java @@ -44,7 +44,7 @@ public void testRenderTextField() { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } From d454384a4b5772e0c1b76e46922c5ed9c4548d3d Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Sun, 13 Feb 2022 10:00:20 +0100 Subject: [PATCH 3/4] WW-5168 Reverts condition in if statement --- .../org/apache/struts2/views/java/simple/CheckboxHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/CheckboxHandler.java b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/CheckboxHandler.java index 6f0e9651bb..6fe4a8bb73 100644 --- a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/CheckboxHandler.java +++ b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/CheckboxHandler.java @@ -52,7 +52,7 @@ public void generate() throws IOException { start("input", attrs); end("input"); - if (!submitUnchecked) { + if (submitUnchecked) { //hidden input attrs = new Attributes(); From fe7959e5d879fdefb1eeea4794d1bbddb7b6b5ef Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Sun, 13 Feb 2022 10:19:01 +0100 Subject: [PATCH 4/4] WW-5168 Adjusts tests to flipped if condition --- .../org/apache/struts2/views/java/simple/CheckboxTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java index 8bb915d89c..d7d56ec0ac 100644 --- a/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java +++ b/plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/CheckboxTest.java @@ -41,7 +41,7 @@ public void testRenderCheckbox() { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } @@ -60,7 +60,7 @@ public void testRenderUncheckCheckbox() { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); } @@ -72,7 +72,7 @@ public void testRenderCheckboxWithNameValue() { map.putAll(tag.getParameters()); theme.renderTag(getTagName(), context); String output = writer.getBuffer().toString(); - String expected = s(""); + String expected = s(""); assertEquals(expected, output); }