Search in sources :

Example 26 with ModelAndView

use of cn.taketoday.web.view.ModelAndView in project today-framework by TAKETODAY.

the class ParameterizableViewControllerTests method viewName.

@Test
public void viewName() throws Exception {
    this.controller.setViewName("view");
    ModelAndView modelAndView = this.controller.handleRequest(this.context);
    assertThat(modelAndView.getViewName()).isEqualTo("view");
}
Also used : ModelAndView(cn.taketoday.web.view.ModelAndView) Test(org.junit.jupiter.api.Test)

Example 27 with ModelAndView

use of cn.taketoday.web.view.ModelAndView in project today-framework by TAKETODAY.

the class ParameterizableViewControllerTests method handleRequestHttpOptions.

@Test
public void handleRequestHttpOptions() throws Exception {
    this.request.setMethod(HttpMethod.OPTIONS.name());
    ModelAndView mav = this.controller.handleRequest(this.context);
    assertThat(mav).isNull();
    assertThat(response.getHeader("Allow")).isEqualTo("GET,HEAD,OPTIONS");
}
Also used : ModelAndView(cn.taketoday.web.view.ModelAndView) Test(org.junit.jupiter.api.Test)

Example 28 with ModelAndView

use of cn.taketoday.web.view.ModelAndView in project today-framework 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);
}
Also used : RedirectModel(cn.taketoday.web.view.RedirectModel) ModelAndView(cn.taketoday.web.view.ModelAndView)

Example 29 with ModelAndView

use of cn.taketoday.web.view.ModelAndView in project today-framework by TAKETODAY.

the class ModelAndViewReturnValueHandler method handleModelAndView.

/**
 * Resolve {@link ModelAndView} return type
 *
 * @since 2.3.3
 */
public final void handleModelAndView(RequestContext context, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
    if (modelAndView != null) {
        View view = modelAndView.getView();
        String viewName = modelAndView.getViewName();
        BindingContext bindingContext = context.getBindingContext();
        bindingContext.addAllAttributes(modelAndView.getModel());
        if (viewName != null) {
            delegate.renderView(context, viewName);
        } else if (view != null) {
            delegate.renderView(context, view);
        }
    }
}
Also used : BindingContext(cn.taketoday.web.BindingContext) View(cn.taketoday.web.view.View) ModelAndView(cn.taketoday.web.view.ModelAndView)

Example 30 with ModelAndView

use of cn.taketoday.web.view.ModelAndView in project today-framework by TAKETODAY.

the class VoidReturnValueHandler method handleReturnValue.

/**
 * mainly for ModelAndView
 *
 * @param context Current HTTP request context
 * @param handler Target HTTP handler
 * @param returnValue Handler execution result
 * Or {@link HandlerExceptionHandler} return value
 */
@Override
public void handleReturnValue(RequestContext context, Object handler, @Nullable Object returnValue) throws Exception {
    BindingContext bindingContext = context.getBindingContext();
    if (bindingContext.hasModelAndView()) {
        ModelAndView modelAndView = bindingContext.getModelAndView();
        // user constructed a ModelAndView hold in context
        returnValueHandler.handleModelAndView(context, null, modelAndView);
    }
}
Also used : ModelAndView(cn.taketoday.web.view.ModelAndView) BindingContext(cn.taketoday.web.BindingContext)

Aggregations

ModelAndView (cn.taketoday.web.view.ModelAndView)56 Test (org.junit.jupiter.api.Test)28 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)26 MockServletRequestContext (cn.taketoday.web.servlet.MockServletRequestContext)24 PathPatternsParameterizedTest (cn.taketoday.web.view.PathPatternsParameterizedTest)24 RequestContext (cn.taketoday.web.RequestContext)22 RedirectModel (cn.taketoday.web.view.RedirectModel)6 BindingContext (cn.taketoday.web.BindingContext)4 StaticWebApplicationContext (cn.taketoday.web.context.support.StaticWebApplicationContext)4 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)2 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)2 RedirectView (cn.taketoday.web.view.RedirectView)2 View (cn.taketoday.web.view.View)2