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 2020/11/25 16:14:07 UTC

[struts] 01/02: Fixes translating id in Form tag

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

lukaszlenart pushed a commit to branch struts-2-5-x
in repository https://gitbox.apache.org/repos/asf/struts.git

commit dfa8fb3e4c3c3220f72135fa779006d9dde747bf
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Wed Nov 25 17:12:57 2020 +0100

    Fixes translating id in Form tag
---
 .../main/java/org/apache/struts2/components/Form.java |  2 +-
 .../org/apache/struts2/views/jsp/ui/FormTagTest.java  | 19 +++++++++++++++++++
 .../org/apache/struts2/views/jsp/ui/Formtag-29.txt    |  3 +++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/struts2/components/Form.java b/core/src/main/java/org/apache/struts2/components/Form.java
index 9758cf3..44bdd09 100644
--- a/core/src/main/java/org/apache/struts2/components/Form.java
+++ b/core/src/main/java/org/apache/struts2/components/Form.java
@@ -221,7 +221,7 @@ public class Form extends ClosingUIBean {
     @Override
     protected void populateComponentHtmlId(Form form) {
         if (id != null) {
-            addParameter("id", escape(id));
+            super.populateComponentHtmlId(null);
         }
 
         // if no id given, it will be tried to generate it from the action attribute
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java
index 27d79ce..2b19563 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/FormTagTest.java
@@ -186,6 +186,25 @@ public class FormTagTest extends AbstractUITagTest {
         verify(FormTag.class.getResource("Formtag-1.txt"));
     }
 
+    public void testFormId() throws Exception {
+
+        request.setupGetServletPath("/testAction");
+
+        TestAction testAction = (TestAction) action;
+        testAction.setFoo("bar");
+
+        FormTag tag = new FormTag();
+        tag.setPageContext(pageContext);
+        tag.setMethod("post");
+        tag.setAction("myAction");
+        tag.setId("myid-%{foo}");
+
+        tag.doStartTag();
+        tag.doEndTag();
+
+        verify(FormTag.class.getResource("Formtag-29.txt"));
+    }
+
      public void testFormNoNameOrId() throws Exception {
 
         request.setupGetServletPath("/testAction");
diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-29.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-29.txt
new file mode 100644
index 0000000..1337f57
--- /dev/null
+++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-29.txt
@@ -0,0 +1,3 @@
+<form id="myid-bar" name="myid-bar" action="myAction" method="post">
+  <table class="wwFormTable"></table>
+</form>