From 55ca7a5b345b00898f43e7dd5af61ea9268beba0 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Sun, 7 Jan 2024 11:37:10 +0100 Subject: [PATCH] WW-5365 Reverts changes introduced in WW-5192 to allow evaluate the value attribute --- .../org/apache/struts2/components/Radio.java | 8 ---- .../java/org/apache/struts2/TestAction.java | 9 +++++ .../struts2/views/jsp/ui/RadioTest.java | 37 ++++++++++++++++++- .../apache/struts2/views/jsp/ui/Radio-11.txt | 4 ++ 4 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 core/src/test/resources/org/apache/struts2/views/jsp/ui/Radio-11.txt diff --git a/core/src/main/java/org/apache/struts2/components/Radio.java b/core/src/main/java/org/apache/struts2/components/Radio.java index 7ef81000ad..5c59e70ec5 100644 --- a/core/src/main/java/org/apache/struts2/components/Radio.java +++ b/core/src/main/java/org/apache/struts2/components/Radio.java @@ -66,10 +66,6 @@ protected String getDefaultTemplate() { return TEMPLATE; } - public void evaluateExtraParams() { - super.evaluateExtraParams(); - } - /** * Radio tag requires lazy evaluation as list of tags is dynamically generated using * @@ -80,8 +76,4 @@ protected boolean lazyEvaluation() { return true; } - protected Class getValueClassType() { - return String.class; - } - } diff --git a/core/src/test/java/org/apache/struts2/TestAction.java b/core/src/test/java/org/apache/struts2/TestAction.java index 5543b44623..77f784a618 100644 --- a/core/src/test/java/org/apache/struts2/TestAction.java +++ b/core/src/test/java/org/apache/struts2/TestAction.java @@ -53,6 +53,7 @@ public class TestAction extends ActionSupport { private Long id; private List enumList; private List intList; + private Boolean someBool; private final Map texts = new HashMap<>(); @@ -254,4 +255,12 @@ public List getIntList() { public void setIntList(List intList) { this.intList = intList; } + + public Boolean getSomeBool() { + return someBool; + } + + public void setSomeBool(Boolean someBool) { + this.someBool = someBool; + } } diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/RadioTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/RadioTest.java index 72e4cbf06c..47a5caad7b 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/RadioTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/RadioTest.java @@ -64,6 +64,37 @@ public void testMapWithBooleanAsKey() throws Exception { strutsBodyTagsAreReflectionEqual(tag, freshTag)); } + public void testMapWithBooleanAsKeyWithoutForceValue() throws Exception { + TestAction testAction = (TestAction) action; + + Map map = new LinkedHashMap<>(); + map.put(Boolean.TRUE, "male"); + map.put(Boolean.FALSE, "female"); + testAction.setMap(map); + + testAction.setSomeBool(false); + + RadioTag tag = new RadioTag(); + tag.setPageContext(pageContext); + tag.setLabel("mylabel"); + tag.setName("myname"); + tag.setValue("someBool"); + tag.setList("map"); + tag.setTheme("simple"); + + tag.doStartTag(); + tag.doEndTag(); + + verify(RadioTag.class.getResource("Radio-11.txt")); + + // Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag(). + RadioTag freshTag = new RadioTag(); + freshTag.setPageContext(pageContext); + assertFalse("Tag state after doEndTag() under default tag clear state is equal to new Tag with pageContext/parent set. " + + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", + strutsBodyTagsAreReflectionEqual(tag, freshTag)); + } + public void testMapWithBooleanAsKey_clearTagStateSet() throws Exception { TestAction testAction = (TestAction) action; @@ -165,12 +196,13 @@ public void testMapCheckedUsingEnum() throws Exception { List enumList = new ArrayList<>(Arrays.asList(SomeEnum.values())); testAction.setEnumList(enumList); + testAction.setStatus(SomeEnum.INIT); RadioTag tag = new RadioTag(); tag.setTheme("simple"); tag.setPageContext(pageContext); tag.setName("status"); - tag.setValue("INIT"); + tag.setValue("status"); tag.setList("enumList"); tag.doStartTag(); @@ -191,13 +223,14 @@ public void testMapCheckedUsingEnum_clearTagStateSet() throws Exception { List enumList = new ArrayList<>(Arrays.asList(SomeEnum.values())); testAction.setEnumList(enumList); + testAction.setStatus(SomeEnum.INIT); RadioTag tag = new RadioTag(); tag.setPerformClearTagStateForTagPoolingServers(true); // Explicitly request tag state clearing. tag.setTheme("simple"); tag.setPageContext(pageContext); tag.setName("status"); - tag.setValue("INIT"); + tag.setValue("status"); tag.setList("enumList"); tag.doStartTag(); diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Radio-11.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Radio-11.txt new file mode 100644 index 0000000000..8f591387b9 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Radio-11.txt @@ -0,0 +1,4 @@ + + + +