[struts] branch WW-5117-reorders-stack created (now 4afa345)

2021-03-06 Thread lukaszlenart
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch WW-5117-reorders-stack
in repository https://gitbox.apache.org/repos/asf/struts.git.


  at 4afa345  WW-5117 Moves action on top just before the tag

This branch includes the following new commits:

 new 4afa345  WW-5117 Moves action on top just before the tag

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




[struts] 01/01: WW-5117 Moves action on top just before the tag

2021-03-06 Thread lukaszlenart
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5117-reorders-stack
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 4afa345c659c0fe75cd3a4c01dff749dcd0e84ea
Author: Lukasz Lenart 
AuthorDate: Sat Mar 6 16:06:23 2021 +0100

WW-5117 Moves action on top just before the tag
---
 .../components/template/FreemarkerTemplateEngine.java   | 11 ---
 .../resources/template/simple/dynamic-attributes.ftl|  2 +-
 core/src/test/java/org/apache/struts2/TestAction.java   | 12 +++-
 .../org/apache/struts2/views/jsp/ui/HiddenTest.java | 17 +
 .../org/apache/struts2/views/jsp/ui/Hidden-3.txt|  5 +
 5 files changed, 42 insertions(+), 5 deletions(-)

diff --git 
a/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java
 
b/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java
index a272697..b3cb544 100644
--- 
a/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java
+++ 
b/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java
@@ -64,7 +64,7 @@ public class FreemarkerTemplateEngine extends 
BaseTemplateEngine {
 public void setFreemarkerManager(FreemarkerManager mgr) {
 this.freemarkerManager = mgr;
 }
-
+
 public void renderTemplate(TemplateRenderingContext templateContext) 
throws Exception {
// get the various items required from the stack
 ValueStack stack = templateContext.getStack();
@@ -144,15 +144,20 @@ public class FreemarkerTemplateEngine extends 
BaseTemplateEngine {
 }
 };
 
+LOG.debug("Puts action on the top of the stack, just before the tag");
+Object actionFromStack = stack.pop();
 try {
 stack.push(templateContext.getTag());
+stack.push(actionFromStack);
 template.process(model, writer);
 } finally {
-stack.pop();
+stack.pop(); // removes action
+stack.pop(); // removes tag
+stack.push(actionFromStack); // puts back action
 }
 }
 
 protected String getSuffix() {
 return "ftl";
 }
-}
\ No newline at end of file
+}
diff --git a/core/src/main/resources/template/simple/dynamic-attributes.ftl 
b/core/src/main/resources/template/simple/dynamic-attributes.ftl
index a6e3943..95de4b7 100644
--- a/core/src/main/resources/template/simple/dynamic-attributes.ftl
+++ b/core/src/main/resources/template/simple/dynamic-attributes.ftl
@@ -29,4 +29,4 @@
   
  ${aKey}="${value?html}"<#rt/>
 <#rt/>
-<#rt/>
\ No newline at end of file
+<#rt/>
diff --git a/core/src/test/java/org/apache/struts2/TestAction.java 
b/core/src/test/java/org/apache/struts2/TestAction.java
index 97fa175..35b48b3 100644
--- a/core/src/test/java/org/apache/struts2/TestAction.java
+++ b/core/src/test/java/org/apache/struts2/TestAction.java
@@ -49,6 +49,7 @@ public class TestAction extends ActionSupport {
 private List list3;
 private SomeEnum status = SomeEnum.COMPLETED;
 private Float floatNumber;
+private Long id;
 
 private final Map texts = new HashMap();
 
@@ -213,7 +214,7 @@ public class TestAction extends ActionSupport {
public void setStatus(SomeEnum status) {
this.status = status;
}
-
+
 public List getStatusList() {
return Arrays.asList(SomeEnum.values());
 }
@@ -225,4 +226,13 @@ public class TestAction extends ActionSupport {
 public void setFloatNumber(Float floatNumber) {
 this.floatNumber = floatNumber;
 }
+
+public Long getId() {
+return id;
+}
+
+public void setId(Long id) {
+this.id = id;
+}
+
 }
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/HiddenTest.java 
b/core/src/test/java/org/apache/struts2/views/jsp/ui/HiddenTest.java
index 37b5303..e66fc5a 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/ui/HiddenTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/HiddenTest.java
@@ -62,6 +62,23 @@ public class HiddenTest extends AbstractUITagTest {
 verify(TextFieldTag.class.getResource("Hidden-2.txt"));
 }
 
+public void testDynamicAttributes() throws Exception {
+TestAction testAction = (TestAction) action;
+testAction.setId(27357L);
+
+HiddenTag tag = new HiddenTag();
+tag.setPageContext(pageContext);
+tag.setId("einszwei");
+tag.setName("first");
+tag.setValue("%{id}");
+tag.setDynamicAttribute("", "data-wuffmiauww", "%{id}");
+
+tag.doStartTag();
+tag.doEndTag();
+
+verify(TextFieldTag.class.getResource("Hidden-3.txt"));
+}
+
 /**
  * Initialize a map of {@link 
org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
  * property testing. Will be used when calling {@link 
#verif