You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by am...@apache.org on 2019/02/04 20:06:38 UTC

[struts] branch master updated: WW-4991 Not existing property in listValueKey throws exception

This is an automated email from the ASF dual-hosted git repository.

amashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/struts.git


The following commit(s) were added to refs/heads/master by this push:
     new f6e0cde  WW-4991 Not existing property in listValueKey throws exception
f6e0cde is described below

commit f6e0cdeb67540ceacff6bcdddd4f167907650640
Author: Aleksandr Mashchenko <am...@apache.org>
AuthorDate: Mon Feb 4 22:06:26 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 c1664f0..5c37a4b 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 d007074..e096cb7 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>