use of org.springframework.web.servlet.support.RequestDataValueProcessor in project spring-framework by spring-projects.
the class FormTag method processAction.
/**
* 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, getHttpMethod());
}
return action;
}
use of org.springframework.web.servlet.support.RequestDataValueProcessor in project spring-framework by spring-projects.
the class FormTagTests method requestDataValueProcessorHooks.
@Test
public void requestDataValueProcessorHooks() throws Exception {
String action = "/my/form?foo=bar";
RequestDataValueProcessor processor = getMockRequestDataValueProcessor();
given(processor.processAction(this.request, action, "post")).willReturn(action);
given(processor.getExtraHiddenFields(this.request)).willReturn(Collections.singletonMap("key", "value"));
this.tag.doStartTag();
this.tag.doEndTag();
this.tag.doFinally();
String output = getOutput();
assertEquals("<div>\n<input type=\"hidden\" name=\"key\" value=\"value\" />\n</div>", getInputTag(output));
assertFormTagOpened(output);
assertFormTagClosed(output);
}
use of org.springframework.web.servlet.support.RequestDataValueProcessor in project spring-framework by spring-projects.
the class RedirectViewTests method updateTargetUrl.
@Test
public void updateTargetUrl() throws Exception {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
wac.setServletContext(new MockServletContext());
wac.refresh();
RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
RedirectView rv = new RedirectView();
// Init RedirectView with WebAppCxt
rv.setApplicationContext(wac);
rv.setUrl("/path");
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
rv.render(new ModelMap(), request, response);
verify(mockProcessor).processUrl(request, "/path");
}
use of org.springframework.web.servlet.support.RequestDataValueProcessor in project spring-framework by spring-projects.
the class RedirectViewTests method updateTargetUrlWithContextLoader.
@Test
public void updateTargetUrlWithContextLoader() throws Exception {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
MockServletContext servletContext = new MockServletContext();
ContextLoader contextLoader = new ContextLoader(wac);
contextLoader.initWebApplicationContext(servletContext);
try {
RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
RedirectView rv = new RedirectView();
rv.setUrl("/path");
given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
rv.render(new ModelMap(), request, response);
verify(mockProcessor).processUrl(request, "/path");
} finally {
contextLoader.closeWebApplicationContext(servletContext);
}
}
use of org.springframework.web.servlet.support.RequestDataValueProcessor in project spring-framework by spring-projects.
the class UrlTag method doEndTag.
@Override
public int doEndTag() throws JspException {
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) {
// print the url to the writer
try {
pageContext.getOut().print(url);
} catch (IOException ex) {
throw new JspException(ex);
}
} else {
// store the url as a variable
pageContext.setAttribute(var, url, scope);
}
return EVAL_PAGE;
}
Aggregations