Prepend context/servlet path to FormTag action

The Form tag now fills in the context and servlet path if not present
in the specified action.

Issue: SPR-8684
This commit is contained in:
Rossen Stoyanchev
2013-01-14 18:19:44 -05:00
parent ad91fa63fa
commit ad025b59c5
3 changed files with 56 additions and 6 deletions

View File

@@ -166,6 +166,50 @@ public class FormTagTests extends AbstractHtmlElementTagTests {
assertAttributeNotPresent(output, "name");
}
public void testPrependServletPath() throws Exception {
this.request.setContextPath("/myApp");
this.request.setServletPath("/main");
this.request.setPathInfo("/index.html");
String commandName = "myCommand";
String action = "/form.html";
String enctype = "my/enctype";
String method = "POST";
String onsubmit = "onsubmit";
String onreset = "onreset";
this.tag.setCommandName(commandName);
this.tag.setAction(action);
this.tag.setMethod(method);
this.tag.setEnctype(enctype);
this.tag.setOnsubmit(onsubmit);
this.tag.setOnreset(onreset);
int result = this.tag.doStartTag();
assertEquals(Tag.EVAL_BODY_INCLUDE, result);
assertEquals("Form attribute not exposed", commandName,
getPageContext().getAttribute(FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE));
result = this.tag.doEndTag();
assertEquals(Tag.EVAL_PAGE, result);
this.tag.doFinally();
assertNull("Form attribute not cleared after tag ends",
getPageContext().getAttribute(FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE));
String output = getOutput();
assertFormTagOpened(output);
assertFormTagClosed(output);
assertContainsAttribute(output, "action", "/myApp/main/form.html");
assertContainsAttribute(output, "method", method);
assertContainsAttribute(output, "enctype", enctype);
assertContainsAttribute(output, "onsubmit", onsubmit);
assertContainsAttribute(output, "onreset", onreset);
assertAttributeNotPresent(output, "name");
}
public void testWithNullResolvedCommand() throws Exception {
try {
tag.setCommandName("${null}");