You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2021/11/10 07:36:29 UTC
[struts] 03/03: WW-5129 Simplifies excluding ignored keys with
?filter
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch WW-5129-dynamic-attributes
in repository https://gitbox.apache.org/repos/asf/struts.git
commit e098c5a2c38f6e2b206aba4625849b05a0b57c5f
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Wed Nov 10 08:33:47 2021 +0100
WW-5129 Simplifies excluding ignored keys with ?filter
---
.../template/simple/dynamic-attributes.ftl | 25 +++++++++-------------
.../freemarker/FreemarkerResultMockedTest.java | 13 ++---------
2 files changed, 12 insertions(+), 26 deletions(-)
diff --git a/core/src/main/resources/template/simple/dynamic-attributes.ftl b/core/src/main/resources/template/simple/dynamic-attributes.ftl
index fe82ac6..47a9113 100644
--- a/core/src/main/resources/template/simple/dynamic-attributes.ftl
+++ b/core/src/main/resources/template/simple/dynamic-attributes.ftl
@@ -18,27 +18,22 @@
* under the License.
*/
-->
+<#function acceptKey(key)>
+ <#if dynamic_attributes_ignore??>
+ <#return !key?starts_with(dynamic_attributes_ignore) >
+ <#else>
+ <#return true>
+ </#if>
+</#function>
<#if (parameters.dynamicAttributes?? && parameters.dynamicAttributes?size > 0)><#rt/>
<#assign aKeys = parameters.dynamicAttributes.keySet()><#rt/>
-<#list aKeys as aKey><#rt/>
-<#if dynamic_attributes_ignore??>
-<#if !aKey?starts_with(dynamic_attributes_ignore)>
+<#list aKeys?filter(acceptKey) as aKey><#rt/>
<#assign keyValue = parameters.dynamicAttributes.get(aKey)/>
<#if keyValue?is_string>
- <#assign value = struts.translateVariables(keyValue)!keyValue/>
+ <#assign value = struts.translateVariables(keyValue)!keyValue/>
<#else>
- <#assign value = keyValue?string/>
+ <#assign value = keyValue?string/>
</#if>
${aKey}="${value}"<#rt/>
-</#if>
-<#else>
-<#assign keyValue = parameters.dynamicAttributes.get(aKey)/>
-<#if keyValue?is_string>
- <#assign value = struts.translateVariables(keyValue)!keyValue/>
-<#else>
- <#assign value = keyValue?string/>
-</#if>
- ${aKey}="${value}"<#rt/>
-</#if>
</#list><#rt/>
</#if><#rt/>
diff --git a/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java b/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java
index a78bcf1..99cd484 100644
--- a/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java
+++ b/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java
@@ -113,12 +113,7 @@ public class FreemarkerResultMockedTest extends StrutsInternalTestCase {
ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request, configurationManager);
dispatcher.serviceAction(request, response, mapping);
- String expectedJDK17 =
- "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" placeholder=\"input\" foo=\"bar\"/>"
- + "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" placeholder=\"input\" foo=\"bar\"/>"
- + "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" break=\"true\"/>"
- + "<input type=\"text\" name=\"required\" value=\"\" id=\"required\" required=\"true\"/>";
- String expectedJDK18 =
+ String expected =
"<input type=\"text\" name=\"test\" value=\"\" id=\"test\" foo=\"bar\" placeholder=\"input\"/>"
+ "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" foo=\"bar\" placeholder=\"input\"/>"
+ "<input type=\"text\" name=\"test\" value=\"\" id=\"test\" break=\"true\"/>"
@@ -126,11 +121,7 @@ public class FreemarkerResultMockedTest extends StrutsInternalTestCase {
String result = stringWriter.toString();
- if (result.contains("id=\"test\" foo=\"bar\"")) {
- assertEquals(expectedJDK18, result);
- } else {
- assertEquals(expectedJDK17, result);
- }
+ assertEquals(expected, result);
}
public void testManualListInTemplate() throws Exception {