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 c6dbd3fa9..a935c0e95 100644 --- a/core/src/main/java/org/apache/struts2/components/Form.java +++ b/core/src/main/java/org/apache/struts2/components/Form.java @@ -36,6 +36,7 @@ import com.opensymphony.xwork2.validator.Validator; import org.apache.struts2.StrutsConstants; import org.apache.struts2.views.annotations.StrutsTag; import org.apache.struts2.views.annotations.StrutsTagAttribute; +import org.apache.commons.lang.xwork.StringUtils; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -153,28 +154,18 @@ public class Form extends ClosingUIBean { */ protected void evaluateExtraParams() { super.evaluateExtraParams(); - - //boolean isAjax = "ajax".equalsIgnoreCase(this.theme); - if (validate != null) { addParameter("validate", findValue(validate, Boolean.class)); } - // calculate the action and namespace - /*String action = null; - if (this.action != null) { - // if it isn't specified, we'll make somethig up - action = findString(this.action); + if (name == null) { + //make the name the same as the id + String id = (String) getParameters().get("id"); + if (StringUtils.isNotEmpty(id)) { + addParameter("name", id); + } } - if (Dispatcher.getInstance().isPortletSupportActive() && PortletActionContext.isPortletRequest()) { - evaluateExtraParamsPortletRequest(namespace, action); - } else { - String namespace = determineNamespace(this.namespace, getStack(), - request); - evaluateExtraParamsServletRequest(action, namespace, isAjax); - }*/ - if (onsubmit != null) { addParameter("onsubmit", findString(onsubmit)); } 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 ad27a1622..70b050692 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 @@ -130,6 +130,7 @@ public class FormTagTest extends AbstractUITagTest { tag.setEnctype("myEncType"); tag.setTitle("mytitle"); tag.setOnsubmit("submitMe()"); + tag.setId("myid"); tag.doStartTag(); tag.doEndTag(); @@ -137,6 +138,28 @@ public class FormTagTest extends AbstractUITagTest { verify(FormTag.class.getResource("Formtag-1.txt")); } + public void testFormNoNameOrId() throws Exception { + + request.setupGetServletPath("/testAction"); + + TestAction testAction = (TestAction) action; + testAction.setFoo("bar"); + + FormTag tag = new FormTag(); + tag.setPageContext(pageContext); + tag.setMethod("post"); + tag.setAcceptcharset("UTF-8"); + tag.setAction("myAction"); + tag.setEnctype("myEncType"); + tag.setTitle("mytitle"); + tag.setOnsubmit("submitMe()"); + + tag.doStartTag(); + tag.doEndTag(); + + verify(FormTag.class.getResource("Formtag-25.txt")); + } + /** * This test with form tag validation enabled. Js validation script will appear * cause action submited by the form is intercepted by validation interceptor which diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-1.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-1.txt index ea63acc52..8bd3a47df 100644 --- a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-1.txt +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-1.txt @@ -1,4 +1,4 @@ -
+
diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-25.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-25.txt new file mode 100644 index 000000000..26a827664 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-25.txt @@ -0,0 +1,4 @@ +
+ +
+
\ No newline at end of file diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-4.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-4.txt index e50067486..35c1895d7 100644 --- a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-4.txt +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-4.txt @@ -1,4 +1,4 @@ -
+
diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-7.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-7.txt index 205207851..0fb96c875 100644 --- a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-7.txt +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-7.txt @@ -1,4 +1,4 @@ -
+