Skip to content

Commit

Permalink
WW-5365 Reverts changes introduced in WW-5192 to allow evaluate the v…
Browse files Browse the repository at this point in the history
…alue attribute
  • Loading branch information
lukaszlenart committed Jan 7, 2024
1 parent ecd02de commit 55ca7a5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
8 changes: 0 additions & 8 deletions core/src/main/java/org/apache/struts2/components/Radio.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <s:iterator/>
*
Expand All @@ -80,8 +76,4 @@ protected boolean lazyEvaluation() {
return true;
}

protected Class<?> getValueClassType() {
return String.class;
}

}
9 changes: 9 additions & 0 deletions core/src/test/java/org/apache/struts2/TestAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class TestAction extends ActionSupport {
private Long id;
private List<SomeEnum> enumList;
private List<Integer> intList;
private Boolean someBool;

private final Map<String, String> texts = new HashMap<>();

Expand Down Expand Up @@ -254,4 +255,12 @@ public List<Integer> getIntList() {
public void setIntList(List<Integer> intList) {
this.intList = intList;
}

public Boolean getSomeBool() {
return someBool;
}

public void setSomeBool(Boolean someBool) {
this.someBool = someBool;
}
}
37 changes: 35 additions & 2 deletions core/src/test/java/org/apache/struts2/views/jsp/ui/RadioTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,37 @@ public void testMapWithBooleanAsKey() throws Exception {
strutsBodyTagsAreReflectionEqual(tag, freshTag));
}

public void testMapWithBooleanAsKeyWithoutForceValue() throws Exception {
TestAction testAction = (TestAction) action;

Map<Boolean, String> 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;

Expand Down Expand Up @@ -165,12 +196,13 @@ public void testMapCheckedUsingEnum() throws Exception {

List<SomeEnum> 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();
Expand All @@ -191,13 +223,14 @@ public void testMapCheckedUsingEnum_clearTagStateSet() throws Exception {

List<SomeEnum> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<input type="radio" name="myname" id="mynametrue" value="true"/>
<label for="mynametrue">male</label>
<input type="radio" name="myname" id="mynamefalse" checked="checked" value="false"/>
<label for="mynamefalse">female</label>

0 comments on commit 55ca7a5

Please sign in to comment.