SPR-7943 Add interface for HDIV integration and delegate to it from JSP form tags.
This commit is contained in:
parent
8b8be39d9f
commit
c257afa515
|
|
@ -20,12 +20,14 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import javax.servlet.jsp.jstl.core.Config;
|
import javax.servlet.jsp.jstl.core.Config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.MessageSourceResolvable;
|
import org.springframework.context.MessageSourceResolvable;
|
||||||
import org.springframework.context.NoSuchMessageException;
|
import org.springframework.context.NoSuchMessageException;
|
||||||
|
|
@ -80,6 +82,12 @@ public class RequestContext {
|
||||||
*/
|
*/
|
||||||
public static final String WEB_APPLICATION_CONTEXT_ATTRIBUTE = RequestContext.class.getName() + ".CONTEXT";
|
public static final String WEB_APPLICATION_CONTEXT_ATTRIBUTE = RequestContext.class.getName() + ".CONTEXT";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the bean to use to look up in an implementation of
|
||||||
|
* {@link RequestDataValueProcessor} has been configured.
|
||||||
|
*/
|
||||||
|
private static final String REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME = "requestDataValueProcessor";
|
||||||
|
|
||||||
protected static final boolean jstlPresent = ClassUtils.isPresent("javax.servlet.jsp.jstl.core.Config",
|
protected static final boolean jstlPresent = ClassUtils.isPresent("javax.servlet.jsp.jstl.core.Config",
|
||||||
RequestContext.class.getClassLoader());
|
RequestContext.class.getClassLoader());
|
||||||
|
|
||||||
|
|
@ -99,6 +107,8 @@ public class RequestContext {
|
||||||
|
|
||||||
private UrlPathHelper urlPathHelper;
|
private UrlPathHelper urlPathHelper;
|
||||||
|
|
||||||
|
private RequestDataValueProcessor requestDataValueProcessor;
|
||||||
|
|
||||||
private Map<String, Errors> errorsMap;
|
private Map<String, Errors> errorsMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -212,8 +222,16 @@ public class RequestContext {
|
||||||
this.defaultHtmlEscape = WebUtils.getDefaultHtmlEscape(this.webApplicationContext.getServletContext());
|
this.defaultHtmlEscape = WebUtils.getDefaultHtmlEscape(this.webApplicationContext.getServletContext());
|
||||||
|
|
||||||
this.urlPathHelper = new UrlPathHelper();
|
this.urlPathHelper = new UrlPathHelper();
|
||||||
}
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.requestDataValueProcessor = this.webApplicationContext.getBean(
|
||||||
|
REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME, RequestDataValueProcessor.class);
|
||||||
|
}
|
||||||
|
catch (NoSuchBeanDefinitionException ex) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the fallback locale for this context. <p>The default implementation checks for a JSTL locale attribute
|
* Determine the fallback locale for this context. <p>The default implementation checks for a JSTL locale attribute
|
||||||
* in request, session or application scope; if not found, returns the <code>HttpServletRequest.getLocale()</code>.
|
* in request, session or application scope; if not found, returns the <code>HttpServletRequest.getLocale()</code>.
|
||||||
|
|
@ -347,6 +365,15 @@ public class RequestContext {
|
||||||
return this.urlPathHelper;
|
return this.urlPathHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the RequestDataValueProcessor instance to use obtained from the
|
||||||
|
* WebApplicationContext under the name {@code "requestDataValueProcessor"}.
|
||||||
|
* Or {@code null} if no matching bean was found.
|
||||||
|
*/
|
||||||
|
public RequestDataValueProcessor getRequestDataValueProcessor() {
|
||||||
|
return this.requestDataValueProcessor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the context path of the original request, that is, the path that indicates the current web application.
|
* Return the context path of the original request, that is, the path that indicates the current web application.
|
||||||
* This is useful for building links to other resources within the application. <p>Delegates to the UrlPathHelper
|
* This is useful for building links to other resources within the application. <p>Delegates to the UrlPathHelper
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2011 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.web.servlet.support;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A contract for inspecting and potentially modifying request data values such
|
||||||
|
* as URL query parameters or form field values before they are rendered by a
|
||||||
|
* view or before a redirect.
|
||||||
|
*
|
||||||
|
* <p>Implementations may use this contract for example as part of a solution
|
||||||
|
* to provide data integrity, confidentiality, protection against cross-site
|
||||||
|
* request forgery (CSRF), and others or for other tasks such as automatically
|
||||||
|
* adding a hidden field to all forms and URLs.
|
||||||
|
*
|
||||||
|
* <p>View technologies that support this contract can obtain an instance to
|
||||||
|
* delegate to via {@link RequestContext#getRequestDataValueProcessor()}.
|
||||||
|
*
|
||||||
|
* @author Rossen Stoyanchev
|
||||||
|
* @since 3.1
|
||||||
|
*/
|
||||||
|
public interface RequestDataValueProcessor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked when a new form action is rendered.
|
||||||
|
* @param request the current request
|
||||||
|
* @param action the form action
|
||||||
|
* @return the action to use, possibly modified
|
||||||
|
*/
|
||||||
|
String processAction(HttpServletRequest request, String action);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked when a form field value is rendered.
|
||||||
|
* @param request the current request
|
||||||
|
* @param name the form field name
|
||||||
|
* @param value the form field value
|
||||||
|
* @param type the form field type ("text", "hidden", etc.)
|
||||||
|
* @return the form field value to use, possibly modified
|
||||||
|
*/
|
||||||
|
String processFormFieldValue(HttpServletRequest request, String name, String value, String type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked after all form fields have been rendered.
|
||||||
|
* @param request the current request
|
||||||
|
* @return additional hidden form fields to be added, or {@code null}
|
||||||
|
*/
|
||||||
|
Map<String, String> getExtraHiddenFields(HttpServletRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked when a URL is about to be rendered or redirected to.
|
||||||
|
* @param request the current request
|
||||||
|
* @param url the URL value
|
||||||
|
* @return the URL to use, possibly modified
|
||||||
|
*/
|
||||||
|
String processUrl(HttpServletRequest request, String url);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -22,12 +22,15 @@ import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.jsp.JspException;
|
import javax.servlet.jsp.JspException;
|
||||||
import javax.servlet.jsp.PageContext;
|
import javax.servlet.jsp.PageContext;
|
||||||
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
||||||
import org.springframework.web.util.ExpressionEvaluationUtils;
|
import org.springframework.web.util.ExpressionEvaluationUtils;
|
||||||
import org.springframework.web.util.HtmlUtils;
|
import org.springframework.web.util.HtmlUtils;
|
||||||
import org.springframework.web.util.JavaScriptUtils;
|
import org.springframework.web.util.JavaScriptUtils;
|
||||||
|
|
@ -168,6 +171,13 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
|
||||||
@Override
|
@Override
|
||||||
public int doEndTag() throws JspException {
|
public int doEndTag() throws JspException {
|
||||||
String url = createUrl();
|
String url = createUrl();
|
||||||
|
|
||||||
|
RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
|
||||||
|
ServletRequest request = this.pageContext.getRequest();
|
||||||
|
if ((processor != null) && (request instanceof HttpServletRequest)) {
|
||||||
|
url = processor.processUrl((HttpServletRequest) request, url);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.var == null) {
|
if (this.var == null) {
|
||||||
// print the url to the writer
|
// print the url to the writer
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ public abstract class AbstractCheckedElementTag extends AbstractHtmlInputElement
|
||||||
* bound value.
|
* bound value.
|
||||||
*/
|
*/
|
||||||
protected void renderFromValue(Object item, Object value, TagWriter tagWriter) throws JspException {
|
protected void renderFromValue(Object item, Object value, TagWriter tagWriter) throws JspException {
|
||||||
tagWriter.writeAttribute("value", convertToDisplayString(value));
|
String displayValue = convertToDisplayString(value);
|
||||||
|
tagWriter.writeAttribute("value", processFieldValue(getName(), displayValue, getInputType()));
|
||||||
if (isOptionSelected(value) || (value != item && isOptionSelected(item))) {
|
if (isOptionSelected(value) || (value != item && isOptionSelected(item))) {
|
||||||
tagWriter.writeAttribute("checked", "checked");
|
tagWriter.writeAttribute("checked", "checked");
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +65,7 @@ public abstract class AbstractCheckedElementTag extends AbstractHtmlInputElement
|
||||||
* <code>true</code>.
|
* <code>true</code>.
|
||||||
*/
|
*/
|
||||||
protected void renderFromBoolean(Boolean boundValue, TagWriter tagWriter) throws JspException {
|
protected void renderFromBoolean(Boolean boundValue, TagWriter tagWriter) throws JspException {
|
||||||
tagWriter.writeAttribute("value", "true");
|
tagWriter.writeAttribute("value", processFieldValue(getName(), "true", getInputType()));
|
||||||
if (boundValue) {
|
if (boundValue) {
|
||||||
tagWriter.writeAttribute("checked", "checked");
|
tagWriter.writeAttribute("checked", "checked");
|
||||||
}
|
}
|
||||||
|
|
@ -87,4 +88,10 @@ public abstract class AbstractCheckedElementTag extends AbstractHtmlInputElement
|
||||||
@Override
|
@Override
|
||||||
protected abstract int writeTagContent(TagWriter tagWriter) throws JspException;
|
protected abstract int writeTagContent(TagWriter tagWriter) throws JspException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the type of the HTML input element to generate:
|
||||||
|
* "checkbox" or "radio".
|
||||||
|
*/
|
||||||
|
protected abstract String getInputType();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,9 @@
|
||||||
package org.springframework.web.servlet.tags.form;
|
package org.springframework.web.servlet.tags.form;
|
||||||
|
|
||||||
import java.beans.PropertyEditor;
|
import java.beans.PropertyEditor;
|
||||||
|
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.jsp.JspException;
|
import javax.servlet.jsp.JspException;
|
||||||
import javax.servlet.jsp.PageContext;
|
import javax.servlet.jsp.PageContext;
|
||||||
|
|
||||||
|
|
@ -24,6 +27,7 @@ import org.springframework.beans.PropertyAccessor;
|
||||||
import org.springframework.core.Conventions;
|
import org.springframework.core.Conventions;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.servlet.support.BindStatus;
|
import org.springframework.web.servlet.support.BindStatus;
|
||||||
|
import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
||||||
import org.springframework.web.servlet.tags.EditorAwareTag;
|
import org.springframework.web.servlet.tags.EditorAwareTag;
|
||||||
import org.springframework.web.servlet.tags.NestedPathTag;
|
import org.springframework.web.servlet.tags.NestedPathTag;
|
||||||
|
|
||||||
|
|
@ -227,6 +231,18 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im
|
||||||
return getDisplayString(value, editor);
|
return getDisplayString(value, editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the given form field through a {@link RequestDataValueProcessor}
|
||||||
|
* instance if one is configured or otherwise returns the same value.
|
||||||
|
*/
|
||||||
|
protected final String processFieldValue(String name, String value, String type) {
|
||||||
|
RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
|
||||||
|
ServletRequest request = this.pageContext.getRequest();
|
||||||
|
if (processor != null && (request instanceof HttpServletRequest)) {
|
||||||
|
value = processor.processFormFieldValue((HttpServletRequest) request, name, value, type);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposes of the {@link BindStatus} instance.
|
* Disposes of the {@link BindStatus} instance.
|
||||||
|
|
|
||||||
|
|
@ -291,10 +291,4 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem
|
||||||
tagWriter.endTag();
|
tagWriter.endTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the type of the HTML input element to generate:
|
|
||||||
* "checkbox" or "radio".
|
|
||||||
*/
|
|
||||||
protected abstract String getInputType();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,9 @@ public class CheckboxTag extends AbstractSingleCheckedElementTag {
|
||||||
// Write out the 'field was present' marker.
|
// Write out the 'field was present' marker.
|
||||||
tagWriter.startTag("input");
|
tagWriter.startTag("input");
|
||||||
tagWriter.writeAttribute("type", "hidden");
|
tagWriter.writeAttribute("type", "hidden");
|
||||||
tagWriter.writeAttribute("name", WebDataBinder.DEFAULT_FIELD_MARKER_PREFIX + getName());
|
String name = WebDataBinder.DEFAULT_FIELD_MARKER_PREFIX + getName();
|
||||||
tagWriter.writeAttribute("value", "on");
|
tagWriter.writeAttribute("name", name);
|
||||||
|
tagWriter.writeAttribute("value", processFieldValue(name, "on", getInputType()));
|
||||||
tagWriter.endTag();
|
tagWriter.endTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,7 +66,7 @@ public class CheckboxTag extends AbstractSingleCheckedElementTag {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeTagDetails(TagWriter tagWriter) throws JspException {
|
protected void writeTagDetails(TagWriter tagWriter) throws JspException {
|
||||||
tagWriter.writeAttribute("type", "checkbox");
|
tagWriter.writeAttribute("type", getInputType());
|
||||||
|
|
||||||
Object boundValue = getBoundValue();
|
Object boundValue = getBoundValue();
|
||||||
Class valueType = getBindStatus().getValueType();
|
Class valueType = getBindStatus().getValueType();
|
||||||
|
|
@ -89,4 +90,9 @@ public class CheckboxTag extends AbstractSingleCheckedElementTag {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getInputType() {
|
||||||
|
return "checkbox";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,9 @@ public class CheckboxesTag extends AbstractMultiCheckedElementTag {
|
||||||
// Write out the 'field was present' marker.
|
// Write out the 'field was present' marker.
|
||||||
tagWriter.startTag("input");
|
tagWriter.startTag("input");
|
||||||
tagWriter.writeAttribute("type", "hidden");
|
tagWriter.writeAttribute("type", "hidden");
|
||||||
tagWriter.writeAttribute("name", WebDataBinder.DEFAULT_FIELD_MARKER_PREFIX + getName());
|
String name = WebDataBinder.DEFAULT_FIELD_MARKER_PREFIX + getName();
|
||||||
tagWriter.writeAttribute("value", "on");
|
tagWriter.writeAttribute("name", name);
|
||||||
|
tagWriter.writeAttribute("value", processFieldValue(name, "on", getInputType()));
|
||||||
tagWriter.endTag();
|
tagWriter.endTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,11 @@
|
||||||
|
|
||||||
package org.springframework.web.servlet.tags.form;
|
package org.springframework.web.servlet.tags.form;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.jsp.JspException;
|
import javax.servlet.jsp.JspException;
|
||||||
import javax.servlet.jsp.PageContext;
|
import javax.servlet.jsp.PageContext;
|
||||||
|
|
@ -25,6 +29,7 @@ import org.springframework.beans.PropertyAccessor;
|
||||||
import org.springframework.core.Conventions;
|
import org.springframework.core.Conventions;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
||||||
import org.springframework.web.util.HtmlUtils;
|
import org.springframework.web.util.HtmlUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -393,7 +398,8 @@ public class FormTag extends AbstractHtmlElementTag {
|
||||||
protected String resolveAction() throws JspException {
|
protected String resolveAction() throws JspException {
|
||||||
String action = getAction();
|
String action = getAction();
|
||||||
if (StringUtils.hasText(action)) {
|
if (StringUtils.hasText(action)) {
|
||||||
return getDisplayString(evaluate(ACTION_ATTRIBUTE, action));
|
action = getDisplayString(evaluate(ACTION_ATTRIBUTE, action));
|
||||||
|
return processAction(action);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String requestUri = getRequestContext().getRequestUri();
|
String requestUri = getRequestContext().getRequestUri();
|
||||||
|
|
@ -406,7 +412,7 @@ public class FormTag extends AbstractHtmlElementTag {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (StringUtils.hasText(requestUri)) {
|
if (StringUtils.hasText(requestUri)) {
|
||||||
return requestUri;
|
return processAction(requestUri);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException("Attribute 'action' is required. " +
|
throw new IllegalArgumentException("Attribute 'action' is required. " +
|
||||||
|
|
@ -415,6 +421,18 @@ public class FormTag extends AbstractHtmlElementTag {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the action through a {@link RequestDataValueProcessor} instance
|
||||||
|
* if one is configured or otherwise returns the action unmodified.
|
||||||
|
*/
|
||||||
|
private String processAction(String action) {
|
||||||
|
RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
|
||||||
|
ServletRequest request = this.pageContext.getRequest();
|
||||||
|
if ((processor != null) && (request instanceof HttpServletRequest)) {
|
||||||
|
action = processor.processAction((HttpServletRequest) request, action);
|
||||||
|
}
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the '<code>form</code>' block tag and removes the form object name
|
* Closes the '<code>form</code>' block tag and removes the form object name
|
||||||
|
|
@ -422,10 +440,28 @@ public class FormTag extends AbstractHtmlElementTag {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int doEndTag() throws JspException {
|
public int doEndTag() throws JspException {
|
||||||
|
RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
|
||||||
|
ServletRequest request = this.pageContext.getRequest();
|
||||||
|
if ((processor != null) && (request instanceof HttpServletRequest)) {
|
||||||
|
writeHiddenFields(processor.getExtraHiddenFields((HttpServletRequest) request));
|
||||||
|
}
|
||||||
this.tagWriter.endTag();
|
this.tagWriter.endTag();
|
||||||
return EVAL_PAGE;
|
return EVAL_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the given values as hidden fields.
|
||||||
|
*/
|
||||||
|
private void writeHiddenFields(Map<String, String> hiddenFields) throws JspException {
|
||||||
|
if (hiddenFields != null) {
|
||||||
|
for (String name : hiddenFields.keySet()) {
|
||||||
|
this.tagWriter.appendValue("<input type=\"hidden\" ");
|
||||||
|
this.tagWriter.appendValue("name=\"" + name + "\" value=\"" + hiddenFields.get(name) + "\" ");
|
||||||
|
this.tagWriter.appendValue("</input>\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the stored {@link TagWriter}.
|
* Clears the stored {@link TagWriter}.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,10 @@ public class HiddenInputTag extends AbstractHtmlElementTag {
|
||||||
tagWriter.startTag("input");
|
tagWriter.startTag("input");
|
||||||
writeDefaultAttributes(tagWriter);
|
writeDefaultAttributes(tagWriter);
|
||||||
tagWriter.writeAttribute("type", "hidden");
|
tagWriter.writeAttribute("type", "hidden");
|
||||||
tagWriter.writeAttribute("value", getDisplayString(getBoundValue(), getPropertyEditor()));
|
String value = getDisplayString(getBoundValue(), getPropertyEditor());
|
||||||
|
tagWriter.writeAttribute("value", processFieldValue(getName(), value, "hidden"));
|
||||||
tagWriter.endTag();
|
tagWriter.endTag();
|
||||||
return SKIP_BODY;
|
return SKIP_BODY;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,12 @@
|
||||||
|
|
||||||
package org.springframework.web.servlet.tags.form;
|
package org.springframework.web.servlet.tags.form;
|
||||||
|
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.jsp.JspException;
|
import javax.servlet.jsp.JspException;
|
||||||
|
|
||||||
|
import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data-binding-aware JSP tag for rendering an HTML '<code>input</code>'
|
* Data-binding-aware JSP tag for rendering an HTML '<code>input</code>'
|
||||||
* element with a '<code>type</code>' of '<code>text</code>'.
|
* element with a '<code>type</code>' of '<code>text</code>'.
|
||||||
|
|
@ -158,7 +162,8 @@ public class InputTag extends AbstractHtmlInputElementTag {
|
||||||
* when the value is written.
|
* when the value is written.
|
||||||
*/
|
*/
|
||||||
protected void writeValue(TagWriter tagWriter) throws JspException {
|
protected void writeValue(TagWriter tagWriter) throws JspException {
|
||||||
tagWriter.writeAttribute("value", getDisplayString(getBoundValue(), getPropertyEditor()));
|
String value = getDisplayString(getBoundValue(), getPropertyEditor());
|
||||||
|
tagWriter.writeAttribute("value", processFieldValue(getName(), value, getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,7 @@ public class OptionTag extends AbstractHtmlElementBodyTag implements BodyTag {
|
||||||
writeOptionalAttribute(tagWriter, "id", resolveId());
|
writeOptionalAttribute(tagWriter, "id", resolveId());
|
||||||
writeOptionalAttributes(tagWriter);
|
writeOptionalAttributes(tagWriter);
|
||||||
String renderedValue = getDisplayString(value, getBindStatus().getEditor());
|
String renderedValue = getDisplayString(value, getBindStatus().getEditor());
|
||||||
|
renderedValue = processFieldValue(getSelectTag().getName(), renderedValue, "option");
|
||||||
tagWriter.writeAttribute(VALUE_ATTRIBUTE, renderedValue);
|
tagWriter.writeAttribute(VALUE_ATTRIBUTE, renderedValue);
|
||||||
if (isSelected(value)) {
|
if (isSelected(value)) {
|
||||||
tagWriter.writeAttribute(SELECTED_ATTRIBUTE, SELECTED_ATTRIBUTE);
|
tagWriter.writeAttribute(SELECTED_ATTRIBUTE, SELECTED_ATTRIBUTE);
|
||||||
|
|
@ -238,6 +239,10 @@ public class OptionTag extends AbstractHtmlElementBodyTag implements BodyTag {
|
||||||
private void assertUnderSelectTag() {
|
private void assertUnderSelectTag() {
|
||||||
TagUtils.assertHasAncestorOfType(this, SelectTag.class, "option", "select");
|
TagUtils.assertHasAncestorOfType(this, SelectTag.class, "option", "select");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SelectTag getSelectTag() {
|
||||||
|
return (SelectTag) findAncestorWithClass(this, SelectTag.class);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isSelected(Object resolvedValue) {
|
private boolean isSelected(Object resolvedValue) {
|
||||||
return SelectedValueComparator.isSelected(getBindStatus(), resolvedValue);
|
return SelectedValueComparator.isSelected(getBindStatus(), resolvedValue);
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,19 @@ package org.springframework.web.servlet.tags.form;
|
||||||
import java.beans.PropertyEditor;
|
import java.beans.PropertyEditor;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.jsp.JspException;
|
import javax.servlet.jsp.JspException;
|
||||||
|
import javax.servlet.jsp.PageContext;
|
||||||
|
|
||||||
import org.springframework.beans.BeanWrapper;
|
import org.springframework.beans.BeanWrapper;
|
||||||
import org.springframework.beans.PropertyAccessorFactory;
|
import org.springframework.beans.PropertyAccessorFactory;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.servlet.support.BindStatus;
|
import org.springframework.web.servlet.support.BindStatus;
|
||||||
|
import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
||||||
|
import org.springframework.web.servlet.support.RequestContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides supporting functionality to render a list of '<code>option</code>'
|
* Provides supporting functionality to render a list of '<code>option</code>'
|
||||||
|
|
@ -222,6 +228,8 @@ class OptionWriter {
|
||||||
|
|
||||||
String valueDisplayString = getDisplayString(value);
|
String valueDisplayString = getDisplayString(value);
|
||||||
String labelDisplayString = getDisplayString(label);
|
String labelDisplayString = getDisplayString(label);
|
||||||
|
|
||||||
|
valueDisplayString = processOptionValue(valueDisplayString);
|
||||||
|
|
||||||
// allows render values to handle some strange browser compat issues.
|
// allows render values to handle some strange browser compat issues.
|
||||||
tagWriter.writeAttribute("value", valueDisplayString);
|
tagWriter.writeAttribute("value", valueDisplayString);
|
||||||
|
|
@ -245,6 +253,14 @@ class OptionWriter {
|
||||||
return ValueFormatter.getDisplayString(value, editor, this.htmlEscape);
|
return ValueFormatter.getDisplayString(value, editor, this.htmlEscape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the option value before it is written.
|
||||||
|
* The default implementation simply returns the same value unchanged.
|
||||||
|
*/
|
||||||
|
protected String processOptionValue(String resolvedValue) {
|
||||||
|
return resolvedValue;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether the supplied values matched the selected value.
|
* Determine whether the supplied values matched the selected value.
|
||||||
* Delegates to {@link SelectedValueComparator#isSelected}.
|
* Delegates to {@link SelectedValueComparator#isSelected}.
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.web.servlet.tags.form;
|
package org.springframework.web.servlet.tags.form;
|
||||||
|
|
||||||
import javax.servlet.jsp.JspException;
|
import javax.servlet.jsp.JspException;
|
||||||
|
import javax.servlet.jsp.tagext.TagSupport;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
@ -145,26 +146,26 @@ public class OptionsTag extends AbstractHtmlElementTag {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int writeTagContent(TagWriter tagWriter) throws JspException {
|
protected int writeTagContent(TagWriter tagWriter) throws JspException {
|
||||||
assertUnderSelectTag();
|
SelectTag selectTag = getSelectTag();
|
||||||
Object items = getItems();
|
Object items = getItems();
|
||||||
Object itemsObject = null;
|
Object itemsObject = null;
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
itemsObject = (items instanceof String ? evaluate("items", items) : items);
|
itemsObject = (items instanceof String ? evaluate("items", items) : items);
|
||||||
} else {
|
} else {
|
||||||
Class<?> selectTagBoundType = ((SelectTag) findAncestorWithClass(this, SelectTag.class))
|
Class<?> selectTagBoundType = selectTag.getBindStatus().getValueType();
|
||||||
.getBindStatus().getValueType();
|
|
||||||
if (selectTagBoundType != null && selectTagBoundType.isEnum()) {
|
if (selectTagBoundType != null && selectTagBoundType.isEnum()) {
|
||||||
itemsObject = selectTagBoundType.getEnumConstants();
|
itemsObject = selectTagBoundType.getEnumConstants();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (itemsObject != null) {
|
if (itemsObject != null) {
|
||||||
|
String selectName = selectTag.getName();
|
||||||
String itemValue = getItemValue();
|
String itemValue = getItemValue();
|
||||||
String itemLabel = getItemLabel();
|
String itemLabel = getItemLabel();
|
||||||
String valueProperty =
|
String valueProperty =
|
||||||
(itemValue != null ? ObjectUtils.getDisplayString(evaluate("itemValue", itemValue)) : null);
|
(itemValue != null ? ObjectUtils.getDisplayString(evaluate("itemValue", itemValue)) : null);
|
||||||
String labelProperty =
|
String labelProperty =
|
||||||
(itemLabel != null ? ObjectUtils.getDisplayString(evaluate("itemLabel", itemLabel)) : null);
|
(itemLabel != null ? ObjectUtils.getDisplayString(evaluate("itemLabel", itemLabel)) : null);
|
||||||
OptionsWriter optionWriter = new OptionsWriter(itemsObject, valueProperty, labelProperty);
|
OptionsWriter optionWriter = new OptionsWriter(selectName, itemsObject, valueProperty, labelProperty);
|
||||||
optionWriter.writeOptions(tagWriter);
|
optionWriter.writeOptions(tagWriter);
|
||||||
}
|
}
|
||||||
return SKIP_BODY;
|
return SKIP_BODY;
|
||||||
|
|
@ -184,8 +185,9 @@ public class OptionsTag extends AbstractHtmlElementTag {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertUnderSelectTag() {
|
private SelectTag getSelectTag() {
|
||||||
TagUtils.assertHasAncestorOfType(this, SelectTag.class, "options", "select");
|
TagUtils.assertHasAncestorOfType(this, SelectTag.class, "options", "select");
|
||||||
|
return (SelectTag) findAncestorWithClass(this, SelectTag.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -198,9 +200,12 @@ public class OptionsTag extends AbstractHtmlElementTag {
|
||||||
* Inner class that adapts OptionWriter for multiple options to be rendered.
|
* Inner class that adapts OptionWriter for multiple options to be rendered.
|
||||||
*/
|
*/
|
||||||
private class OptionsWriter extends OptionWriter {
|
private class OptionsWriter extends OptionWriter {
|
||||||
|
|
||||||
|
private final String selectName;
|
||||||
|
|
||||||
public OptionsWriter(Object optionSource, String valueProperty, String labelProperty) {
|
public OptionsWriter(String selectName, Object optionSource, String valueProperty, String labelProperty) {
|
||||||
super(optionSource, getBindStatus(), valueProperty, labelProperty, isHtmlEscape());
|
super(optionSource, getBindStatus(), valueProperty, labelProperty, isHtmlEscape());
|
||||||
|
this.selectName = selectName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -213,6 +218,12 @@ public class OptionsTag extends AbstractHtmlElementTag {
|
||||||
writeOptionalAttribute(tagWriter, "id", resolveId());
|
writeOptionalAttribute(tagWriter, "id", resolveId());
|
||||||
writeOptionalAttributes(tagWriter);
|
writeOptionalAttributes(tagWriter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String processOptionValue(String value) {
|
||||||
|
return processFieldValue(this.selectName, value, "option");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ public class PasswordInputTag extends InputTag {
|
||||||
if (this.showPassword) {
|
if (this.showPassword) {
|
||||||
super.writeValue(tagWriter);
|
super.writeValue(tagWriter);
|
||||||
} else {
|
} else {
|
||||||
tagWriter.writeAttribute("value", "");
|
tagWriter.writeAttribute("value", processFieldValue(getName(), "", getType()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,14 @@ public class RadioButtonTag extends AbstractSingleCheckedElementTag {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeTagDetails(TagWriter tagWriter) throws JspException {
|
protected void writeTagDetails(TagWriter tagWriter) throws JspException {
|
||||||
tagWriter.writeAttribute("type", "radio");
|
tagWriter.writeAttribute("type", getInputType());
|
||||||
Object resolvedValue = evaluate("value", getValue());
|
Object resolvedValue = evaluate("value", getValue());
|
||||||
renderFromValue(resolvedValue, tagWriter);
|
renderFromValue(resolvedValue, tagWriter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getInputType() {
|
||||||
|
return "radio";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package org.springframework.web.servlet.tags.form;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.jsp.JspException;
|
import javax.servlet.jsp.JspException;
|
||||||
|
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
@ -207,12 +208,17 @@ public class SelectTag extends AbstractHtmlInputElementTag {
|
||||||
if (items != EMPTY) {
|
if (items != EMPTY) {
|
||||||
Object itemsObject = evaluate("items", items);
|
Object itemsObject = evaluate("items", items);
|
||||||
if (itemsObject != null) {
|
if (itemsObject != null) {
|
||||||
|
final String selectName = getName();
|
||||||
String valueProperty = (getItemValue() != null ?
|
String valueProperty = (getItemValue() != null ?
|
||||||
ObjectUtils.getDisplayString(evaluate("itemValue", getItemValue())) : null);
|
ObjectUtils.getDisplayString(evaluate("itemValue", getItemValue())) : null);
|
||||||
String labelProperty = (getItemLabel() != null ?
|
String labelProperty = (getItemLabel() != null ?
|
||||||
ObjectUtils.getDisplayString(evaluate("itemLabel", getItemLabel())) : null);
|
ObjectUtils.getDisplayString(evaluate("itemLabel", getItemLabel())) : null);
|
||||||
OptionWriter optionWriter =
|
OptionWriter optionWriter =
|
||||||
new OptionWriter(itemsObject, getBindStatus(), valueProperty, labelProperty, isHtmlEscape());
|
new OptionWriter(itemsObject, getBindStatus(), valueProperty, labelProperty, isHtmlEscape()) {
|
||||||
|
protected String processOptionValue(String resolvedValue) {
|
||||||
|
return processFieldValue(selectName, resolvedValue, "option");
|
||||||
|
}
|
||||||
|
};
|
||||||
optionWriter.writeOptions(tagWriter);
|
optionWriter.writeOptions(tagWriter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -238,8 +244,9 @@ public class SelectTag extends AbstractHtmlInputElementTag {
|
||||||
if (isMultiple()) {
|
if (isMultiple()) {
|
||||||
tagWriter.startTag("input");
|
tagWriter.startTag("input");
|
||||||
tagWriter.writeAttribute("type", "hidden");
|
tagWriter.writeAttribute("type", "hidden");
|
||||||
tagWriter.writeAttribute("name", WebDataBinder.DEFAULT_FIELD_MARKER_PREFIX + getName());
|
String name = WebDataBinder.DEFAULT_FIELD_MARKER_PREFIX + getName();
|
||||||
tagWriter.writeAttribute("value", "1");
|
tagWriter.writeAttribute("name", name);
|
||||||
|
tagWriter.writeAttribute("value", processFieldValue(name, "1", "hidden"));
|
||||||
tagWriter.endTag();
|
tagWriter.endTag();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -305,5 +312,5 @@ public class SelectTag extends AbstractHtmlInputElementTag {
|
||||||
this.tagWriter = null;
|
this.tagWriter = null;
|
||||||
this.pageContext.removeAttribute(LIST_VALUE_PAGE_ATTRIBUTE);
|
this.pageContext.removeAttribute(LIST_VALUE_PAGE_ATTRIBUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,8 @@ public class TextareaTag extends AbstractHtmlInputElementTag {
|
||||||
writeOptionalAttribute(tagWriter, ROWS_ATTRIBUTE, getRows());
|
writeOptionalAttribute(tagWriter, ROWS_ATTRIBUTE, getRows());
|
||||||
writeOptionalAttribute(tagWriter, COLS_ATTRIBUTE, getCols());
|
writeOptionalAttribute(tagWriter, COLS_ATTRIBUTE, getCols());
|
||||||
writeOptionalAttribute(tagWriter, ONSELECT_ATTRIBUTE, getOnselect());
|
writeOptionalAttribute(tagWriter, ONSELECT_ATTRIBUTE, getOnselect());
|
||||||
tagWriter.appendValue(getDisplayString(getBoundValue(), getPropertyEditor()));
|
String value = getDisplayString(getBoundValue(), getPropertyEditor());
|
||||||
|
tagWriter.appendValue(processFieldValue(getName(), value, "textarea"));
|
||||||
tagWriter.endTag();
|
tagWriter.endTag();
|
||||||
return SKIP_BODY;
|
return SKIP_BODY;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,9 @@ import org.springframework.web.servlet.FlashMap;
|
||||||
import org.springframework.web.servlet.HandlerMapping;
|
import org.springframework.web.servlet.HandlerMapping;
|
||||||
import org.springframework.web.servlet.SmartView;
|
import org.springframework.web.servlet.SmartView;
|
||||||
import org.springframework.web.servlet.View;
|
import org.springframework.web.servlet.View;
|
||||||
|
import org.springframework.web.servlet.support.RequestContext;
|
||||||
import org.springframework.web.servlet.support.RequestContextUtils;
|
import org.springframework.web.servlet.support.RequestContextUtils;
|
||||||
|
import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
||||||
import org.springframework.web.util.UriComponents;
|
import org.springframework.web.util.UriComponents;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
import org.springframework.web.util.UriUtils;
|
import org.springframework.web.util.UriUtils;
|
||||||
|
|
@ -228,6 +230,14 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An ApplicationContext is not strictly required for RedirectView.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected boolean isContextRequired() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert model to request parameters and redirect to the given URL.
|
* Convert model to request parameters and redirect to the given URL.
|
||||||
* @see #appendQueryProperties
|
* @see #appendQueryProperties
|
||||||
|
|
@ -240,6 +250,14 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
|
||||||
|
|
||||||
String targetUrl = createTargetUrl(model, request);
|
String targetUrl = createTargetUrl(model, request);
|
||||||
|
|
||||||
|
if (getWebApplicationContext() != null) {
|
||||||
|
RequestContext requestContext = createRequestContext(request, response, model);
|
||||||
|
RequestDataValueProcessor processor = requestContext.getRequestDataValueProcessor();
|
||||||
|
if (processor != null) {
|
||||||
|
targetUrl = processor.processUrl(request, targetUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request);
|
FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request);
|
||||||
if (!CollectionUtils.isEmpty(flashMap)) {
|
if (!CollectionUtils.isEmpty(flashMap)) {
|
||||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(targetUrl).build();
|
UriComponents uriComponents = UriComponentsBuilder.fromUriString(targetUrl).build();
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ import org.springframework.web.servlet.support.BindStatus;
|
||||||
public class OptionTagEnumTests extends AbstractHtmlElementTagTests {
|
public class OptionTagEnumTests extends AbstractHtmlElementTagTests {
|
||||||
|
|
||||||
private OptionTag tag;
|
private OptionTag tag;
|
||||||
|
|
||||||
|
private SelectTag parentTag;
|
||||||
|
|
||||||
protected void onSetUp() {
|
protected void onSetUp() {
|
||||||
this.tag = new OptionTag() {
|
this.tag = new OptionTag() {
|
||||||
|
|
@ -36,7 +38,14 @@ public class OptionTagEnumTests extends AbstractHtmlElementTagTests {
|
||||||
return new TagWriter(getWriter());
|
return new TagWriter(getWriter());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.tag.setParent(new SelectTag());
|
this.parentTag = new SelectTag() {
|
||||||
|
public String getName() {
|
||||||
|
// Should not be used other than to delegate to
|
||||||
|
// RequestDataValueDataProcessor
|
||||||
|
return "testName";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.tag.setParent(this.parentTag);
|
||||||
this.tag.setPageContext(getPageContext());
|
this.tag.setPageContext(getPageContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,7 +53,8 @@ public class OptionTagEnumTests extends AbstractHtmlElementTagTests {
|
||||||
GenericBean testBean = new GenericBean();
|
GenericBean testBean = new GenericBean();
|
||||||
testBean.setCustomEnum(CustomEnum.VALUE_1);
|
testBean.setCustomEnum(CustomEnum.VALUE_1);
|
||||||
getPageContext().getRequest().setAttribute("testBean", testBean);
|
getPageContext().getRequest().setAttribute("testBean", testBean);
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.customEnum", false));
|
String selectName = "testBean.customEnum";
|
||||||
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||||
|
|
||||||
this.tag.setValue("VALUE_1");
|
this.tag.setValue("VALUE_1");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
|
|
||||||
private OptionTag tag;
|
private OptionTag tag;
|
||||||
|
|
||||||
|
private SelectTag parentTag;
|
||||||
|
|
||||||
protected void onSetUp() {
|
protected void onSetUp() {
|
||||||
this.tag = new OptionTag() {
|
this.tag = new OptionTag() {
|
||||||
|
|
@ -56,13 +57,21 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
return new TagWriter(getWriter());
|
return new TagWriter(getWriter());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.tag.setParent(new SelectTag());
|
this.parentTag = new SelectTag() {
|
||||||
|
public String getName() {
|
||||||
|
// Should not be used other than to delegate to
|
||||||
|
// RequestDataValueDataProcessor
|
||||||
|
return "testName";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.tag.setParent(this.parentTag);
|
||||||
this.tag.setPageContext(getPageContext());
|
this.tag.setPageContext(getPageContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCanBeDisabledEvenWhenSelected() throws Exception {
|
public void testCanBeDisabledEvenWhenSelected() throws Exception {
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.name", false));
|
String selectName = "testBean.name";
|
||||||
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||||
this.tag.setValue("bar");
|
this.tag.setValue("bar");
|
||||||
this.tag.setLabel("Bar");
|
this.tag.setLabel("Bar");
|
||||||
this.tag.setDisabled("true");
|
this.tag.setDisabled("true");
|
||||||
|
|
@ -81,7 +90,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRenderNotSelected() throws Exception {
|
public void testRenderNotSelected() throws Exception {
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.name", false));
|
String selectName = "testBean.name";
|
||||||
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||||
this.tag.setValue("bar");
|
this.tag.setValue("bar");
|
||||||
this.tag.setLabel("Bar");
|
this.tag.setLabel("Bar");
|
||||||
int result = this.tag.doStartTag();
|
int result = this.tag.doStartTag();
|
||||||
|
|
@ -101,7 +111,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
String dynamicAttribute1 = "attr1";
|
String dynamicAttribute1 = "attr1";
|
||||||
String dynamicAttribute2 = "attr2";
|
String dynamicAttribute2 = "attr2";
|
||||||
|
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.name", false));
|
String selectName = "testBean.name";
|
||||||
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||||
this.tag.setValue("bar");
|
this.tag.setValue("bar");
|
||||||
this.tag.setLabel("Bar");
|
this.tag.setLabel("Bar");
|
||||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||||
|
|
@ -123,7 +134,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRenderSelected() throws Exception {
|
public void testRenderSelected() throws Exception {
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.name", false));
|
String selectName = "testBean.name";
|
||||||
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||||
this.tag.setId("myOption");
|
this.tag.setId("myOption");
|
||||||
this.tag.setValue("foo");
|
this.tag.setValue("foo");
|
||||||
this.tag.setLabel("Foo");
|
this.tag.setLabel("Foo");
|
||||||
|
|
@ -143,7 +155,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithNoLabel() throws Exception {
|
public void testWithNoLabel() throws Exception {
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.name", false));
|
String selectName = "testBean.name";
|
||||||
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||||
this.tag.setValue("bar");
|
this.tag.setValue("bar");
|
||||||
this.tag.setCssClass("myClass");
|
this.tag.setCssClass("myClass");
|
||||||
this.tag.setOnclick("CLICK");
|
this.tag.setOnclick("CLICK");
|
||||||
|
|
@ -175,7 +188,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithEnum() throws Exception {
|
public void testWithEnum() throws Exception {
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.favouriteColour", false));
|
String selectName = "testBean.favouriteColour";
|
||||||
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||||
|
|
||||||
String value = Colour.GREEN.getCode().toString();
|
String value = Colour.GREEN.getCode().toString();
|
||||||
String label = Colour.GREEN.getLabel();
|
String label = Colour.GREEN.getLabel();
|
||||||
|
|
@ -198,7 +212,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithEnumNotSelected() throws Exception {
|
public void testWithEnumNotSelected() throws Exception {
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.favouriteColour", false));
|
String selectName = "testBean.favouriteColour";
|
||||||
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||||
|
|
||||||
String value = Colour.BLUE.getCode().toString();
|
String value = Colour.BLUE.getCode().toString();
|
||||||
String label = Colour.BLUE.getLabel();
|
String label = Colour.BLUE.getLabel();
|
||||||
|
|
@ -221,7 +236,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithPropertyEditor() throws Exception {
|
public void testWithPropertyEditor() throws Exception {
|
||||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.stringArray", false) {
|
String selectName = "testBean.stringArray";
|
||||||
|
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||||
public PropertyEditor getEditor() {
|
public PropertyEditor getEditor() {
|
||||||
return new StringArrayPropertyEditor();
|
return new StringArrayPropertyEditor();
|
||||||
}
|
}
|
||||||
|
|
@ -249,7 +265,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
public void testWithPropertyEditorStringComparison() throws Exception {
|
public void testWithPropertyEditorStringComparison() throws Exception {
|
||||||
final PropertyEditor testBeanEditor = new TestBeanPropertyEditor();
|
final PropertyEditor testBeanEditor = new TestBeanPropertyEditor();
|
||||||
testBeanEditor.setValue(new TestBean("Sally"));
|
testBeanEditor.setValue(new TestBean("Sally"));
|
||||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.spouse", false) {
|
String selectName = "testBean.spouse";
|
||||||
|
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||||
public PropertyEditor getEditor() {
|
public PropertyEditor getEditor() {
|
||||||
return testBeanEditor;
|
return testBeanEditor;
|
||||||
}
|
}
|
||||||
|
|
@ -272,7 +289,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithCustomObjectSelected() throws Exception {
|
public void testWithCustomObjectSelected() throws Exception {
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.someNumber", false));
|
String selectName = "testBean.someNumber";
|
||||||
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||||
this.tag.setValue("${myNumber}");
|
this.tag.setValue("${myNumber}");
|
||||||
this.tag.setLabel("GBP ${myNumber}");
|
this.tag.setLabel("GBP ${myNumber}");
|
||||||
int result = this.tag.doStartTag();
|
int result = this.tag.doStartTag();
|
||||||
|
|
@ -290,7 +308,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithCustomObjectNotSelected() throws Exception {
|
public void testWithCustomObjectNotSelected() throws Exception {
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.someNumber", false));
|
String selectName = "testBean.someNumber";
|
||||||
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||||
this.tag.setValue("${myOtherNumber}");
|
this.tag.setValue("${myOtherNumber}");
|
||||||
this.tag.setLabel("GBP ${myOtherNumber}");
|
this.tag.setLabel("GBP ${myOtherNumber}");
|
||||||
int result = this.tag.doStartTag();
|
int result = this.tag.doStartTag();
|
||||||
|
|
@ -310,7 +329,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
public void testWithCustomObjectAndEditorSelected() throws Exception {
|
public void testWithCustomObjectAndEditorSelected() throws Exception {
|
||||||
final PropertyEditor floatEditor = new SimpleFloatEditor();
|
final PropertyEditor floatEditor = new SimpleFloatEditor();
|
||||||
floatEditor.setValue(new Float("12.34"));
|
floatEditor.setValue(new Float("12.34"));
|
||||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.someNumber", false) {
|
String selectName = "testBean.someNumber";
|
||||||
|
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||||
public PropertyEditor getEditor() {
|
public PropertyEditor getEditor() {
|
||||||
return floatEditor;
|
return floatEditor;
|
||||||
}
|
}
|
||||||
|
|
@ -334,7 +354,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
|
|
||||||
public void testWithCustomObjectAndEditorNotSelected() throws Exception {
|
public void testWithCustomObjectAndEditorNotSelected() throws Exception {
|
||||||
final PropertyEditor floatEditor = new SimpleFloatEditor();
|
final PropertyEditor floatEditor = new SimpleFloatEditor();
|
||||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.someNumber", false) {
|
String selectName = "testBean.someNumber";
|
||||||
|
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||||
public PropertyEditor getEditor() {
|
public PropertyEditor getEditor() {
|
||||||
return floatEditor;
|
return floatEditor;
|
||||||
}
|
}
|
||||||
|
|
@ -357,7 +378,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAsBodyTag() throws Exception {
|
public void testAsBodyTag() throws Exception {
|
||||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.name", false);
|
String selectName = "testBean.name";
|
||||||
|
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
|
||||||
|
|
||||||
String bodyContent = "some content";
|
String bodyContent = "some content";
|
||||||
|
|
@ -377,7 +399,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAsBodyTagSelected() throws Exception {
|
public void testAsBodyTagSelected() throws Exception {
|
||||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.name", false);
|
String selectName = "testBean.name";
|
||||||
|
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
|
||||||
|
|
||||||
String bodyContent = "some content";
|
String bodyContent = "some content";
|
||||||
|
|
@ -396,7 +419,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAsBodyTagCollapsed() throws Exception {
|
public void testAsBodyTagCollapsed() throws Exception {
|
||||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.name", false);
|
String selectName = "testBean.name";
|
||||||
|
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false);
|
||||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
|
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
|
||||||
|
|
||||||
String bodyContent = "some content";
|
String bodyContent = "some content";
|
||||||
|
|
@ -416,7 +440,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAsBodyTagWithEditor() throws Exception {
|
public void testAsBodyTagWithEditor() throws Exception {
|
||||||
BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.stringArray", false) {
|
String selectName = "testBean.stringArray";
|
||||||
|
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||||
public PropertyEditor getEditor() {
|
public PropertyEditor getEditor() {
|
||||||
return new RulesVariantEditor();
|
return new RulesVariantEditor();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,11 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||||
protected TagWriter createTagWriter() {
|
protected TagWriter createTagWriter() {
|
||||||
return new TagWriter(getWriter());
|
return new TagWriter(getWriter());
|
||||||
}
|
}
|
||||||
|
public String getName() {
|
||||||
|
// Should not be used other than to delegate to
|
||||||
|
// RequestDataValueDataProcessor
|
||||||
|
return "testName";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
selectTag.setPageContext(getPageContext());
|
selectTag.setPageContext(getPageContext());
|
||||||
this.tag.setParent(selectTag);
|
this.tag.setParent(selectTag);
|
||||||
|
|
@ -299,5 +304,5 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||||
RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
|
RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
|
||||||
pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
|
pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,11 @@ public class RedirectViewUriTemplateTests {
|
||||||
private MockHttpServletRequest request;
|
private MockHttpServletRequest request;
|
||||||
|
|
||||||
private MockHttpServletResponse response;
|
private MockHttpServletResponse response;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
request = new MockHttpServletRequest();
|
this.request = new MockHttpServletRequest();
|
||||||
response = new MockHttpServletResponse();
|
this.response = new MockHttpServletResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -47,9 +47,9 @@ public class RedirectViewUriTemplateTests {
|
||||||
|
|
||||||
String baseUrl = "http://url.somewhere.com";
|
String baseUrl = "http://url.somewhere.com";
|
||||||
RedirectView redirectView = new RedirectView(baseUrl + "/{foo}");
|
RedirectView redirectView = new RedirectView(baseUrl + "/{foo}");
|
||||||
redirectView.renderMergedOutputModel(model, request, response);
|
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||||
|
|
||||||
assertEquals(baseUrl + "/bar", response.getRedirectedUrl());
|
assertEquals(baseUrl + "/bar", this.response.getRedirectedUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -59,9 +59,9 @@ public class RedirectViewUriTemplateTests {
|
||||||
|
|
||||||
String baseUrl = "http://url.somewhere.com";
|
String baseUrl = "http://url.somewhere.com";
|
||||||
RedirectView redirectView = new RedirectView(baseUrl + "/context path/{foo}");
|
RedirectView redirectView = new RedirectView(baseUrl + "/context path/{foo}");
|
||||||
redirectView.renderMergedOutputModel(model, request, response);
|
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||||
|
|
||||||
assertEquals(baseUrl + "/context path/bar%2Fbar%20baz", response.getRedirectedUrl());
|
assertEquals(baseUrl + "/context path/bar%2Fbar%20baz", this.response.getRedirectedUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -71,9 +71,9 @@ public class RedirectViewUriTemplateTests {
|
||||||
model.put("fooArr", new String[] { "baz", "bazz" });
|
model.put("fooArr", new String[] { "baz", "bazz" });
|
||||||
|
|
||||||
RedirectView redirectView = new RedirectView("/foo/{foo}");
|
RedirectView redirectView = new RedirectView("/foo/{foo}");
|
||||||
redirectView.renderMergedOutputModel(model, request, response);
|
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||||
|
|
||||||
assertEquals("/foo/bar?fooArr=baz&fooArr=bazz", response.getRedirectedUrl());
|
assertEquals("/foo/bar?fooArr=baz&fooArr=bazz", this.response.getRedirectedUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -82,9 +82,9 @@ public class RedirectViewUriTemplateTests {
|
||||||
model.put("foo", new Long(611));
|
model.put("foo", new Long(611));
|
||||||
|
|
||||||
RedirectView redirectView = new RedirectView("/foo/{foo}");
|
RedirectView redirectView = new RedirectView("/foo/{foo}");
|
||||||
redirectView.renderMergedOutputModel(model, request, response);
|
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||||
|
|
||||||
assertEquals("/foo/611", response.getRedirectedUrl());
|
assertEquals("/foo/611", this.response.getRedirectedUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -98,18 +98,18 @@ public class RedirectViewUriTemplateTests {
|
||||||
currentRequestUriTemplateVars.put("var1", "v1");
|
currentRequestUriTemplateVars.put("var1", "v1");
|
||||||
currentRequestUriTemplateVars.put("name", "v2");
|
currentRequestUriTemplateVars.put("name", "v2");
|
||||||
currentRequestUriTemplateVars.put("var3", "v3");
|
currentRequestUriTemplateVars.put("var3", "v3");
|
||||||
request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, currentRequestUriTemplateVars);
|
this.request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, currentRequestUriTemplateVars);
|
||||||
|
|
||||||
String url = "http://url.somewhere.com";
|
String url = "http://url.somewhere.com";
|
||||||
RedirectView redirectView = new RedirectView(url + "/{key1}/{var1}/{name}");
|
RedirectView redirectView = new RedirectView(url + "/{key1}/{var1}/{name}");
|
||||||
redirectView.renderMergedOutputModel(model, request, response);
|
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||||
|
|
||||||
assertEquals(url + "/value1/v1/value2?key3=value3", response.getRedirectedUrl());
|
assertEquals(url + "/value1/v1/value2?key3=value3", this.response.getRedirectedUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void uriTemplateNullValue() throws Exception {
|
public void uriTemplateNullValue() throws Exception {
|
||||||
new RedirectView("/{foo}").renderMergedOutputModel(new ModelMap(), request, response);
|
new RedirectView("/{foo}").renderMergedOutputModel(new ModelMap(), this.request, this.response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -117,9 +117,9 @@ public class RedirectViewUriTemplateTests {
|
||||||
Map<String, Object> model = new HashMap<String, Object>();
|
Map<String, Object> model = new HashMap<String, Object>();
|
||||||
|
|
||||||
RedirectView redirectView = new RedirectView("");
|
RedirectView redirectView = new RedirectView("");
|
||||||
redirectView.renderMergedOutputModel(model, request, response);
|
redirectView.renderMergedOutputModel(model, this.request, this.response);
|
||||||
|
|
||||||
assertEquals("", response.getRedirectedUrl());
|
assertEquals("", this.response.getRedirectedUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
import org.springframework.web.servlet.View;
|
import org.springframework.web.servlet.View;
|
||||||
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
|
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
|
||||||
|
import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
||||||
import org.springframework.web.servlet.view.AbstractView;
|
import org.springframework.web.servlet.view.AbstractView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -148,6 +149,8 @@ public class VelocityViewTests {
|
||||||
expectLastCall().andReturn(null);
|
expectLastCall().andReturn(null);
|
||||||
wac.getServletContext();
|
wac.getServletContext();
|
||||||
expectLastCall().andReturn(sc).times(3);
|
expectLastCall().andReturn(sc).times(3);
|
||||||
|
wac.getBean("requestDataValueProcessor", RequestDataValueProcessor.class);
|
||||||
|
expectLastCall().andReturn(null);
|
||||||
replay(wac);
|
replay(wac);
|
||||||
|
|
||||||
HttpServletRequest request = new MockHttpServletRequest();
|
HttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
|
@ -203,6 +206,8 @@ public class VelocityViewTests {
|
||||||
expectLastCall().andReturn(null);
|
expectLastCall().andReturn(null);
|
||||||
wac.getServletContext();
|
wac.getServletContext();
|
||||||
expectLastCall().andReturn(sc).times(3);
|
expectLastCall().andReturn(sc).times(3);
|
||||||
|
wac.getBean("requestDataValueProcessor", RequestDataValueProcessor.class);
|
||||||
|
expectLastCall().andReturn(null);
|
||||||
replay(wac);
|
replay(wac);
|
||||||
|
|
||||||
HttpServletRequest request = new MockHttpServletRequest();
|
HttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue