WW-2951 Add a default "name" to form, when it is not set (same as the "id")

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@766376 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2009-04-18 18:48:47 +00:00
parent 149d112b1d
commit 28fd86aa16
6 changed files with 37 additions and 19 deletions
@@ -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));
}
@@ -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
@@ -1,4 +1,4 @@
<form id="myAction" name="myForm" onsubmit="submitMe()" action="myAction" method="post" enctype="myEncType" title="mytitle" accept-charset="UTF-8">
<form id="myid" name="myForm" onsubmit="submitMe()" action="myAction" method="post" enctype="myEncType" title="mytitle" accept-charset="UTF-8">
<table class="wwFormTable">
</table>
</form>
@@ -0,0 +1,4 @@
<form id="myAction" name="myAction" onsubmit="submitMe()" action="myAction" method="post" enctype="myEncType" title="mytitle" accept-charset="UTF-8">
<table class="wwFormTable">
</table>
</form>
@@ -1,4 +1,4 @@
<form id="foo" action="/foo.jsp" method="post">
<form id="foo" name="foo" action="/foo.jsp" method="post">
<table class="wwFormTable">
</table>
</form>
@@ -1,4 +1,4 @@
<form id="test" action="test.html" method="post">
<form id="test" name="test" action="test.html" method="post">
<table class="wwFormTable">
</table>
</form>