Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WW-5365] Reverts changes introduced in WW-5192 to allow evaluate the value attribute of Radio tag #835

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>