use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework by bluecrow1986.
the class RedirectAttributesMethodArgumentResolver method resolveArgument.
@Override
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception {
Assert.state(mavContainer != null, "RedirectAttributes argument only supported on regular handler methods");
ModelMap redirectAttributes;
if (binderFactory != null) {
DataBinder dataBinder = binderFactory.createBinder(webRequest, null, DataBinder.DEFAULT_OBJECT_NAME);
redirectAttributes = new RedirectAttributesModelMap(dataBinder);
} else {
redirectAttributes = new RedirectAttributesModelMap();
}
mavContainer.setRedirectModel(redirectAttributes);
return redirectAttributes;
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework by bluecrow1986.
the class ModelAndViewMethodReturnValueHandlerTests method handleRedirectAttributesWithViewName.
@Test
public void handleRedirectAttributesWithViewName() throws Exception {
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
mavContainer.setRedirectModel(redirectAttributes);
ModelAndView mav = new ModelAndView("redirect:viewName", "attrName", "attrValue");
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
ModelMap model = mavContainer.getModel();
assertThat(mavContainer.getViewName()).isEqualTo("redirect:viewName");
assertThat(model.get("attrName")).isEqualTo("attrValue");
assertThat(model).isSameAs(redirectAttributes);
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework by bluecrow1986.
the class ModelAndViewMethodReturnValueHandlerTests method handleRedirectAttributesWithCustomPrefix.
@Test
public void handleRedirectAttributesWithCustomPrefix() throws Exception {
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
mavContainer.setRedirectModel(redirectAttributes);
ModelAndView mav = new ModelAndView("myRedirect:viewName", "attrName", "attrValue");
handler.setRedirectPatterns("myRedirect:*");
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
ModelMap model = mavContainer.getModel();
assertThat(mavContainer.getViewName()).isEqualTo("myRedirect:viewName");
assertThat(model.get("attrName")).isEqualTo("attrValue");
assertThat(model).isSameAs(redirectAttributes);
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework by bluecrow1986.
the class ModelAndViewMethodReturnValueHandlerTests method handleRedirectAttributesWithViewReference.
@Test
public void handleRedirectAttributesWithViewReference() throws Exception {
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
mavContainer.setRedirectModel(redirectAttributes);
ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue");
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
assertThat(mavContainer.getView().getClass()).isEqualTo(RedirectView.class);
assertThat(mavContainer.getModel().get("attrName")).isEqualTo("attrValue");
assertThat(mavContainer.getModel()).as("RedirectAttributes should be used if controller redirects").isSameAs(redirectAttributes);
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework by bluecrow1986.
the class ModelAndViewMethodReturnValueHandlerTests method handleRedirectAttributesWithoutRedirect.
@Test
public void handleRedirectAttributesWithoutRedirect() throws Exception {
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
mavContainer.setRedirectModel(redirectAttributes);
ModelAndView mav = new ModelAndView();
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
ModelMap model = mavContainer.getModel();
assertThat(mavContainer.getView()).isEqualTo(null);
assertThat(mavContainer.getModel().isEmpty()).isTrue();
assertThat(model).as("RedirectAttributes should not be used if controller doesn't redirect").isNotSameAs(redirectAttributes);
}
Aggregations