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

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

Introduction

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

Prototype

public boolean isReference() 

Source Link

Document

Return whether we use a view reference, i.e.

Usage

From source file:com.cnd.greencube.web.base.interceptor.ListInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView != null && modelAndView.isReference()) {
        String viewName = modelAndView.getViewName();
        if (StringUtils.startsWith(viewName, REDIRECT_VIEW_NAME_PREFIX)) {
            String listQuery = WebUtils.getCookie(request, LIST_QUERY_COOKIE_NAME);
            if (StringUtils.isNotEmpty(listQuery)) {
                if (StringUtils.startsWith(listQuery, "?")) {
                    listQuery = listQuery.substring(1);
                }//  w  ww  .j  av a  2  s . co  m
                if (StringUtils.contains(viewName, "?")) {
                    modelAndView.setViewName(viewName + "&" + listQuery);
                } else {
                    modelAndView.setViewName(viewName + "?" + listQuery);
                }
            }
        }
    }
}

From source file:net.groupbuy.interceptor.ListInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView != null && modelAndView.isReference()) {
        String viewName = modelAndView.getViewName();
        if (StringUtils.startsWith(viewName, REDIRECT_VIEW_NAME_PREFIX)) {
            String listQuery = WebUtils.getCookie(request, LIST_QUERY_COOKIE_NAME);
            if (StringUtils.isNotEmpty(listQuery)) {
                if (StringUtils.startsWith(listQuery, "?")) {
                    listQuery = listQuery.substring(1);
                }/*from   w ww  .j  a v a2s .co  m*/
                if (StringUtils.contains(viewName, "?")) {
                    modelAndView.setViewName(viewName + "&" + listQuery);
                } else {
                    modelAndView.setViewName(viewName + "?" + listQuery);
                }
                WebUtils.removeCookie(request, response, LIST_QUERY_COOKIE_NAME);
            }
        }
    }
}

From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.support.ReadOnlyHandlerInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    try {//w  w w  . j ava2s .  c o m
        if (modelAndView.isReference() && !modelAndView.getViewName().startsWith("redirect:")) {
            String eid = parseeid(request);
            if (eid != null) {
                Map<String, Object> model = modelAndView.getModel();
                model.put("readOnly", settingsService.isReadOnly(eid));
            }
        }
    } catch (Exception e) {
        logger.info("Unable to populate readonly attribute into model", e);
    }
}

From source file:org.jnap.core.mvc.async.AsyncRequestInterceptor.java

@Override
public void onStateChange(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event)
        throws IOException {
    System.out.println("AsyncRequestInterceptor.onStateChange()");
    System.out.println(event.getMessage());
    HttpServletRequest req = event.getResource().getRequest();
    HttpServletResponse res = event.getResource().getResponse();
    try {//from w w  w.  j  ava 2 s . com
        ModelAndView mv = (ModelAndView) event.getMessage();
        View view = null;
        if (mv.isReference()) {
            view = this.viewResolver.resolveViewName(mv.getViewName(), this.localeResolver.resolveLocale(req));
        } else {
            view = mv.getView();
            if (view == null) {

            }
        }
        view.render(mv.getModelMap(), req, res);
    } catch (Exception e) {
        throw new IOException(e.getMessage(), e);
    }
}

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

/**
 * Render the given ModelAndView.//from  w  w  w.  jav a  2s. com
 * <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//from  ww w.j av a 2 s  . co  m
 * @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.DispatcherServletMod.java

/**
 * Render the given ModelAndView.// ww  w.  j  a  v a 2 s  . co  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.  java  2  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() + "'");
    }
    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  www .j ava  2s  .  co  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 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);
}