use of cn.taketoday.web.view.RedirectModel in project today-infrastructure by TAKETODAY.
the class AbstractUrlViewController method handleRequestInternal.
/**
* Retrieves the URL path to use for lookup and delegates to
* {@link #getViewNameForRequest}. Also adds the content of
* {@link RequestContextUtils#getInputRedirectModel(RequestContext)} to the model.
*/
@Override
protected ModelAndView handleRequestInternal(RequestContext request) {
String viewName = getViewNameForRequest(request);
if (log.isTraceEnabled()) {
log.trace("Returning view name '{}'", viewName);
}
RedirectModel model = RequestContextUtils.getInputRedirectModel(request);
if (model != null) {
return new ModelAndView(viewName, model.asMap());
}
return new ModelAndView(viewName);
}
use of cn.taketoday.web.view.RedirectModel in project today-infrastructure by TAKETODAY.
the class UrlFilenameViewControllerTests method withFlashAttributes.
@PathPatternsParameterizedTest
void withFlashAttributes(Function<String, RequestContext> requestFactory) throws Exception {
UrlFilenameViewController controller = new UrlFilenameViewController();
RequestContext request = requestFactory.apply("/index");
request.setAttribute(RedirectModel.INPUT_ATTRIBUTE, new RedirectModel("name", "value"));
ModelAndView mv = controller.handleRequest(request);
assertThat(mv.getViewName()).isEqualTo("index");
assertThat(mv.getModel().size()).isEqualTo(1);
assertThat(mv.getModel().get("name")).isEqualTo("value");
}
use of cn.taketoday.web.view.RedirectModel in project today-framework by TAKETODAY.
the class ModelParameterResolver method resolveParameter.
/**
* Resolve {@link Model} parameter.
*/
@Override
public Object resolveParameter(RequestContext context, ResolvableMethodParameter resolvable) throws Throwable {
if (resolvable.isAssignableTo(RedirectModel.class)) {
// RedirectModel
RedirectModel redirectModel = new RedirectModel();
RedirectModelManager modelManager = getModelManager();
// @since 3.0.3 checking model manager
if (modelManager != null) {
context.setAttribute(RedirectModel.OUTPUT_ATTRIBUTE, redirectModel);
modelManager.saveRedirectModel(context, redirectModel);
}
return redirectModel;
}
if (resolvable.isAssignableTo(ModelAndView.class)) {
return context.modelAndView();
}
// @since 3.0
if (resolvable.is(HttpHeaders.class)) {
return context.requestHeaders();
}
if (resolvable.is(Map.class)) {
// Model Map
return context.asMap();
}
return context;
}
Aggregations