Skip to content

Commit

Permalink
WW-4991 Not existing property in listValueKey throws exception
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-m committed Feb 4, 2019
1 parent 48fe791 commit f6e0cde
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
9 changes: 6 additions & 3 deletions core/src/main/resources/template/simple/radiomap.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
<#if parameters.listValueKey??>
<#-- checks the valueStack for the 'valueKey.' The valueKey is then looked-up in the locale
file for it's localized value. This is then used as a label -->
<#assign itemValue = stack.findString(parameters.listValueKey)/>
<#-- FIXME: find a better way to get the value than a call to @s.text -->
<#assign itemValue><@s.text name="${itemValue}"/></#assign>
<#assign valueKey = stack.findString(parameters.listValueKey)!''/>
<#if valueKey?has_content>
<#assign itemValue = struts.getText(valueKey) />
<#else>
<#assign itemValue = parameters.listValueKey />
</#if>
<#elseif parameters.listValue??>
<#assign itemValue = stack.findString(parameters.listValue)/>
<#else>
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/template/simple/select.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
<#if parameters.listValueKey??>
<#-- checks the valueStack for the 'valueKey.' The valueKey is then looked-up in the locale file for it's
localized value. This is then used as a label -->
<#assign valueKey = stack.findString(parameters.listValueKey) />
<#if valueKey??>
<#assign valueKey = stack.findString(parameters.listValueKey)!'' />
<#if valueKey?has_content>
<#assign itemValue = struts.getText(valueKey) />
<#else>
<#assign itemValue = parameters.listValueKey />
Expand Down
15 changes: 15 additions & 0 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 @@ -196,6 +196,21 @@ public void testDynamicAttributes() throws Exception {
verify(RadioTag.class.getResource("Radio-7.txt"));
}

public void testNotExistingListValueKey() throws Exception {
RadioTag tag = new RadioTag();
tag.setName("myname");
tag.setLabel("mylabel");
tag.setList("#{'a':'aaa', 'b':'bbb', 'c':'ccc'}");
tag.setListValueKey("notExistingProperty");

tag.setPageContext(pageContext);

tag.doStartTag();
tag.doEndTag();

verify(SelectTag.class.getResource("Radio-8.txt"));
}

private void prepareTagGeneric(RadioTag tag) {
TestAction testAction = (TestAction) action;
testAction.setFoo("bar");
Expand Down
15 changes: 15 additions & 0 deletions core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,21 @@ public void testEnumList() throws Exception {
verify(SelectTag.class.getResource("Select-13.txt"));
}

public void testNotExistingListValueKey() throws Exception {
SelectTag tag = new SelectTag();
tag.setName("foo");
tag.setLabel("mylabel");
tag.setList("#{'a':'aaa', 'b':'bbb', 'c':'ccc'}");
tag.setListValueKey("notExistingProperty");

tag.setPageContext(pageContext);

tag.doStartTag();
tag.doEndTag();

verify(SelectTag.class.getResource("Select-16.txt"));
}

public class IdName {
private String name;
private Integer id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<tr>
<td class="tdLabel"><label for="myname" class="label">mylabel:</label></td>
<td class="tdInput">
<input type="radio" name="myname" id="mynamea" value="a"/><label for="mynamea">notExistingProperty</label>
<input type="radio" name="myname" id="mynameb" value="b"/><label for="mynameb">notExistingProperty</label>
<input type="radio" name="myname" id="mynamec" value="c"/><label for="mynamec">notExistingProperty</label>
</td>
</tr>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<tr>
<td class="tdLabel"><label for="foo" class="label">mylabel:</label></td>
<td class="tdInput">
<select name="foo" id="foo">
<option value="a">notExistingProperty</option>
<option value="b">notExistingProperty</option>
<option value="c">notExistingProperty</option>
</select>
</td>
</tr>

0 comments on commit f6e0cde

Please sign in to comment.