Example usage for org.springframework.web.servlet ModelAndView getModelInternal

List of usage examples for org.springframework.web.servlet ModelAndView getModelInternal

Introduction

In this page you can find the example usage for org.springframework.web.servlet ModelAndView getModelInternal.

Prototype

@Nullable
protected Map<String, Object> getModelInternal() 

Source Link

Document

Return the model map.

Usage

From source file:com.mystudy.source.spring.mvc.DispatcherServlet.java

/**
 * Render the given ModelAndView./* w  w  w .  ja  v a2 s .  c  o m*/
 * <p>This is the last stage in handling a request. It may involve resolving the view by name.
 * @param mv the ModelAndView to render
 * @param request current HTTP servlet request
 * @param response current HTTP servlet response
 * @throws ServletException if view is missing or cannot be resolved
 * @throws Exception if there's a problem rendering the view
 */
protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // Determine locale for request and apply it to the response.
    Locale locale = this.localeResolver.resolveLocale(request);
    response.setLocale(locale);

    View view;
    if (mv.isReference()) {
        // We need to resolve the view name.
        view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);
        if (view == null) {
            throw new ServletException("Could not resolve view with name '" + mv.getViewName()
                    + "' in servlet with name '" + getServletName() + "'");
        }
    } else {
        // No need to lookup: the ModelAndView object contains the actual View object.
        view = mv.getView();
        if (view == null) {
            throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a "
                    + "View object in servlet with name '" + getServletName() + "'");
        }
    }

    // Delegate to the View object for rendering.
    if (logger.isDebugEnabled()) {
        logger.debug("Rendering view [" + view + "] in DispatcherServlet with name '" + getServletName() + "'");
    }
    view.render(mv.getModelInternal(), request, response);
}

From source file:org.springframework.web.portlet.DispatcherPortlet.java

/**
 * Render the given ModelAndView. This is the last stage in handling a request.
 * It may involve resolving the view by name.
 * @param mv the ModelAndView to render// www  .j a va  2  s.  c  om
 * @param request current portlet render request
 * @param response current portlet render response
 * @throws Exception if there's a problem rendering the view
 */
protected void render(ModelAndView mv, PortletRequest request, MimeResponse response) throws Exception {
    View view;
    if (mv.isReference()) {
        // We need to resolve the view name.
        view = resolveViewName(mv.getViewName(), mv.getModelInternal(), request);
        if (view == null) {
            throw new PortletException("Could not resolve view with name '" + mv.getViewName()
                    + "' in portlet with name '" + getPortletName() + "'");
        }
    } else {
        // No need to lookup: the ModelAndView object contains the actual View object.
        Object viewObject = mv.getView();
        if (viewObject == null) {
            throw new PortletException("ModelAndView [" + mv + "] neither contains a view name nor a "
                    + "View object in portlet with name '" + getPortletName() + "'");
        }
        if (!(viewObject instanceof View)) {
            throw new PortletException("View object [" + viewObject
                    + "] is not an instance of [org.springframework.web.servlet.View] - "
                    + "DispatcherPortlet does not support any other view types");
        }
        view = (View) viewObject;
    }

    // Set the content type on the response if needed and if possible.
    // The Portlet spec requires the content type to be set on the RenderResponse;
    // it's not sufficient to let the View set it on the ServletResponse.
    if (response.getContentType() != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Portlet response content type already set to [" + response.getContentType() + "]");
        }
    } else {
        // No Portlet content type specified yet -> use the view-determined type.
        String contentType = view.getContentType();
        if (contentType != null) {
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "Setting portlet response content type to view-determined type [" + contentType + "]");
            }
            response.setContentType(contentType);
        }
    }

    doRender(view, mv.getModelInternal(), request, response);
}

From source file:org.springframework.web.servlet.DispatcherServlet.java

/**
 * Render the given ModelAndView./*from ww  w . j  a v  a2s  .c  om*/
 * <p>This is the last stage in handling a request. It may involve resolving the view by name.
 * @param mv the ModelAndView to render
 * @param request current HTTP servlet request
 * @param response current HTTP servlet response
 * @throws ServletException if view is missing or cannot be resolved
 * @throws Exception if there's a problem rendering the view
 */
protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // Determine locale for request and apply it to the response.
    Locale locale = (this.localeResolver != null ? this.localeResolver.resolveLocale(request)
            : request.getLocale());
    response.setLocale(locale);

    View view;
    String viewName = mv.getViewName();
    if (viewName != null) {
        // We need to resolve the view name.
        view = resolveViewName(viewName, mv.getModelInternal(), locale, request);
        if (view == null) {
            throw new ServletException("Could not resolve view with name '" + mv.getViewName()
                    + "' in servlet with name '" + getServletName() + "'");
        }
    } else {
        // No need to lookup: the ModelAndView object contains the actual View object.
        view = mv.getView();
        if (view == null) {
            throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a "
                    + "View object in servlet with name '" + getServletName() + "'");
        }
    }

    // Delegate to the View object for rendering.
    if (logger.isDebugEnabled()) {
        logger.debug("Rendering view [" + view + "] in DispatcherServlet with name '" + getServletName() + "'");
    }
    try {
        if (mv.getStatus() != null) {
            response.setStatus(mv.getStatus().value());
        }
        view.render(mv.getModelInternal(), request, response);
    } catch (Exception ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Error rendering view [" + view + "] in DispatcherServlet with name '"
                    + getServletName() + "'", ex);
        }
        throw ex;
    }
}

From source file:org.springframework.web.servlet.DispatcherServletMod.java

/**
 * Render the given ModelAndView./*  w w w .  j  a v  a  2s  . c o  m*/
 * <p>
 * This is the last stage in handling a request. It may involve resolving
 * the view by name.
 * 
 * @param mv
 *            the ModelAndView to render
 * @param request
 *            current HTTP servlet request
 * @param response
 *            current HTTP servlet response
 * @throws ServletException
 *             if view is missing or cannot be resolved
 * @throws Exception
 *             if there's a problem rendering the view
 */
protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // Determine locale for request and apply it to the response.
    Locale locale = this.localeResolver.resolveLocale(request);
    response.setLocale(locale);

    View view;
    if (mv.isReference()) {
        // We need to resolve the view name.
        view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);
        if (view == null) {
            throw new ServletException("Could not resolve view with name '" + mv.getViewName()
                    + "' in servlet with name '" + getServletName() + "'");
        }
    } else {
        // No need to lookup: the ModelAndView object contains the actual
        // View object.
        view = mv.getView();
        if (view == null) {
            throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a "
                    + "View object in servlet with name '" + getServletName() + "'");
        }
    }

    // Delegate to the View object for rendering.
    if (logger.isDebugEnabled()) {
        logger.debug("Rendering view [" + view + "] in DispatcherServlet with name '" + getServletName() + "'");
    }
    try {
        view.render(mv.getModelInternal(), request, response);
    } catch (Exception ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Error rendering view [" + view + "] in DispatcherServlet with name '"
                    + getServletName() + "'", ex);
        }
        throw ex;
    }
}

From source file:org.springframework.web.servlet.LogDispatcherServlet.java

/**
 * Render the given ModelAndView.//from   w  w  w  .  j av  a2  s. c om
 * <p>This is the last stage in handling a request. It may involve resolving the view by name.
 * @param mv the ModelAndView to render
 * @param request current HTTP servlet request
 * @param response current HTTP servlet response
 * @throws ServletException if view is missing or cannot be resolved
 * @throws Exception if there's a problem rendering the view
 */
protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // Determine locale for request and apply it to the response.
    Locale locale = this.localeResolver.resolveLocale(request);
    response.setLocale(locale);

    View view;
    if (mv.isReference()) {
        // We need to resolve the view name.
        view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);
        if (view == null) {
            throw new ServletException("Could not resolve view with name '" + mv.getViewName()
                    + "' in servlet with name '" + getServletName() + "'");
        }
    } else {
        // No need to lookup: the ModelAndView object contains the actual View object.
        view = mv.getView();
        if (view == null) {
            throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a "
                    + "View object in servlet with name '" + getServletName() + "'");
        }
    }

    // Delegate to the View object for rendering.
    if (logger.isDebugEnabled()) {
        logger.debug("Rendering view [" + view + "] in DispatcherServlet with name '" + getServletName() + "'");
    }
    try {
        view.render(mv.getModelInternal(), request, response);
    } catch (Exception ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Error rendering view [" + view + "] in DispatcherServlet with name '"
                    + getServletName() + "'", ex);
        }
        throw ex;
    }
}

From source file:org.springframework.web.servlet.SimpleDispatcherServlet.java

/**
 * Render the given ModelAndView./*from w ww.j a v a 2s.c om*/
 * <p>This is the last stage in handling a request. It may involve resolving the view by name.
 * @param mv the ModelAndView to render
 * @param request current HTTP servlet request
 * @param response current HTTP servlet response
 * @throws Exception if there's a problem rendering the view
 */
protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // Determine locale for request and apply it to the response.
    Locale locale = this.localeResolver.resolveLocale(request);
    response.setLocale(locale);

    View view;
    if (mv.isReference()) {
        // We need to resolve the view name.
        view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);
        if (view == null) {
            throw new ServletException("Could not resolve view with name '" + mv.getViewName()
                    + "' in servlet with name '" + getServletName() + "'");
        }
    } else {
        // No need to lookup: the ModelAndView object contains the actual View object.
        view = mv.getView();
        if (view == null) {
            throw new ServletException("ModelAndView [" + mv + "] neither contains a view name nor a "
                    + "View object in servlet with name '" + getServletName() + "'");
        }
    }

    //DEBUG
    Map<String, Object> modelInternal = mv.getModelInternal();
    for (String modelName : modelInternal.keySet()) {
        System.out.println("modelKey: " + modelName);
        System.out.println("modelValue: " + modelInternal.get(modelName));
    }

    // Delegate to the View object for rendering.
    if (logger.isDebugEnabled()) {
        logger.debug("Rendering view [" + view + "] in DispatcherServlet with name '" + getServletName() + "'");
    }
    view.render(mv.getModelInternal(), request, response);
}