mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-3312 Add "includeContext" to Form tag, like the Url tag does (default to true)
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@832087 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -104,8 +104,9 @@ public class Form extends ClosingUIBean {
|
||||
protected String portletMode;
|
||||
protected String windowState;
|
||||
protected String acceptcharset;
|
||||
protected String focusElement;
|
||||
protected boolean includeContext = true;
|
||||
|
||||
protected String focusElement;
|
||||
protected Configuration configuration;
|
||||
protected ObjectFactory objectFactory;
|
||||
protected UrlRenderer urlRenderer;
|
||||
@@ -346,4 +347,9 @@ public class Form extends ClosingUIBean {
|
||||
public void setFocusElement(String focusElement) {
|
||||
this.focusElement = focusElement;
|
||||
}
|
||||
|
||||
@StrutsTagAttribute(description="Whether actual context should be included in URL", type="Boolean", defaultValue="true")
|
||||
public void setIncludeContext(boolean includeContext) {
|
||||
this.includeContext = includeContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ public class ServletUrlRenderer implements UrlRenderer {
|
||||
|
||||
ActionMapping mapping = new ActionMapping(actionName, namespace, actionMethod, formComponent.parameters);
|
||||
String result = UrlHelper.buildUrl(formComponent.actionMapper.getUriFromActionMapping(mapping),
|
||||
formComponent.request, formComponent.response, null);
|
||||
formComponent.request, formComponent.response, null, null, formComponent.includeContext, true);
|
||||
formComponent.addParameter("action", result);
|
||||
|
||||
// let's try to get the actual action class and name
|
||||
@@ -186,7 +186,7 @@ public class ServletUrlRenderer implements UrlRenderer {
|
||||
LOG.warn("No configuration found for the specified action: '" + actionName + "' in namespace: '" + namespace + "'. Form action defaulting to 'action' attribute's literal value.");
|
||||
}
|
||||
|
||||
String result = UrlHelper.buildUrl(action, formComponent.request, formComponent.response, null);
|
||||
String result = UrlHelper.buildUrl(action, formComponent.request, formComponent.response, null, null, formComponent.includeContext, true);
|
||||
formComponent.addParameter("action", result);
|
||||
|
||||
// namespace: cut out anything between the start and the last /
|
||||
|
||||
@@ -49,6 +49,7 @@ public class FormTag extends AbstractClosingTag {
|
||||
protected String windowState;
|
||||
protected String acceptcharset;
|
||||
protected String focusElement;
|
||||
protected boolean includeContext = true;
|
||||
|
||||
public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
|
||||
return new Form(stack, req, res);
|
||||
@@ -68,6 +69,7 @@ public class FormTag extends AbstractClosingTag {
|
||||
form.setWindowState(windowState);
|
||||
form.setAcceptcharset(acceptcharset);
|
||||
form.setFocusElement(focusElement);
|
||||
form.setIncludeContext(includeContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -118,4 +120,8 @@ public class FormTag extends AbstractClosingTag {
|
||||
public void setFocusElement(String focusElement) {
|
||||
this.focusElement = focusElement;
|
||||
}
|
||||
|
||||
public void setIncludeContext(boolean includeContext) {
|
||||
this.includeContext = includeContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +121,14 @@ Please do not edit it directly.
|
||||
<td align="left" valign="top">String</td>
|
||||
<td align="left" valign="top">HTML id attribute</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top">includeContext</td>
|
||||
<td align="left" valign="top">false</td>
|
||||
<td align="left" valign="top">true</td>
|
||||
<td align="left" valign="top">false</td>
|
||||
<td align="left" valign="top">Boolean</td>
|
||||
<td align="left" valign="top">Whether actual context should be included in URL</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top">javascriptTooltip</td>
|
||||
<td align="left" valign="top">false</td>
|
||||
|
||||
@@ -65,6 +65,35 @@ public class FormTagTest extends AbstractUITagTest {
|
||||
|
||||
verify(FormTag.class.getResource("Formtag-9.txt"));
|
||||
}
|
||||
|
||||
public void testFormWithoutContext() throws Exception {
|
||||
request.setupGetContext("somecontext");
|
||||
|
||||
FormTag tag = new FormTag();
|
||||
tag.setTheme("xhtml");
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setAction("testAction");
|
||||
tag.setIncludeContext(false);
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
|
||||
|
||||
verify(FormTag.class.getResource("Formtag-14.txt"));
|
||||
}
|
||||
|
||||
public void testFormWithContext() throws Exception {
|
||||
request.setupGetContext("/somecontext");
|
||||
|
||||
FormTag tag = new FormTag();
|
||||
tag.setTheme("xhtml");
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setAction("testAction");
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
|
||||
|
||||
verify(FormTag.class.getResource("Formtag-13.txt"));
|
||||
}
|
||||
|
||||
public void testFormWithActionAttributeContainingBothActionAndDMIMethod() throws Exception {
|
||||
FormTag tag = new FormTag();
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<form id="testAction" name="testAction" action="/somecontext/testAction.action" method="post">
|
||||
<table class="wwFormTable">
|
||||
</table>
|
||||
</form>
|
||||
@@ -0,0 +1,4 @@
|
||||
<form id="testAction" name="testAction" action="/testAction.action" method="post">
|
||||
<table class="wwFormTable">
|
||||
</table>
|
||||
</form>
|
||||
Reference in New Issue
Block a user