This is an automated email from the ASF dual-hosted git repository. amashchenko pushed a commit to branch struts-2-5-x in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/struts-2-5-x by this push: new 873ca8f WW-4991 Not existing property in listValueKey throws exception new 32e88d1 Merge pull request #322 from aleksandr-m/feature/WW-4991 873ca8f is described below commit 873ca8fa203b7066cbae3333aeb688887df5d16c Author: Aleksandr Mashchenko <amashche...@apache.org> AuthorDate: Wed Jan 30 23:10:06 2019 +0200 WW-4991 Not existing property in listValueKey throws exception --- core/src/main/resources/template/simple/radiomap.ftl | 9 ++++++--- core/src/main/resources/template/simple/select.ftl | 4 ++-- .../java/org/apache/struts2/views/jsp/ui/RadioTest.java | 15 +++++++++++++++ .../java/org/apache/struts2/views/jsp/ui/SelectTest.java | 15 +++++++++++++++ .../resources/org/apache/struts2/views/jsp/ui/Radio-8.txt | 8 ++++++++ .../org/apache/struts2/views/jsp/ui/Select-16.txt | 10 ++++++++++ 6 files changed, 56 insertions(+), 5 deletions(-) diff --git a/core/src/main/resources/template/simple/radiomap.ftl b/core/src/main/resources/template/simple/radiomap.ftl index cdff00e..b44a0be 100644 --- a/core/src/main/resources/template/simple/radiomap.ftl +++ b/core/src/main/resources/template/simple/radiomap.ftl @@ -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> diff --git a/core/src/main/resources/template/simple/select.ftl b/core/src/main/resources/template/simple/select.ftl index a0c17b4..b0144ba 100644 --- a/core/src/main/resources/template/simple/select.ftl +++ b/core/src/main/resources/template/simple/select.ftl @@ -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 /> 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 4932740..1caa5a5 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 @@ -196,6 +196,21 @@ public class RadioTest extends AbstractUITagTest { 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"); diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java index 01f7300..c30b8f5 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java @@ -637,6 +637,21 @@ public class SelectTest extends AbstractUITagTest { 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; diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Radio-8.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Radio-8.txt new file mode 100644 index 0000000..585a0ae --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Radio-8.txt @@ -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> diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Select-16.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Select-16.txt new file mode 100644 index 0000000..609e664 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Select-16.txt @@ -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>