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

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

Introduction

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

Prototype

public boolean hasView() 

Source Link

Document

Indicate whether or not this ModelAndView has a view, either as a view name or as a direct View instance.

Usage

From source file:com.nirwansyah.dicka.springboot.config.ThymeleafInterceptors.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView == null || !modelAndView.hasView()) {
        return;//w  ww . j a v  a2 s  .  co m
    }
    String originalViewName = modelAndView.getViewName();
    modelAndView.addObject("title");
    modelAndView.setViewName(DEFAULT_LAYOUT);
    modelAndView.addObject(DEFAULT_VIEW_ATTRIBUTE_NAME, originalViewName);
}

From source file:com.nkapps.billing.configs.LayoutInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView == null || !modelAndView.hasView()) {
        return;/*www. j av a  2  s  . com*/
    }
    String originalViewName = modelAndView.getViewName();
    if (isRedirectOrForward(originalViewName)) {
        return;
    }
    if (originalViewName.endsWith(WITHOUT_LAYOUT)) {
        modelAndView.setViewName(originalViewName.replace(WITHOUT_LAYOUT, ""));
        return;
    }
    modelAndView.setViewName(DEFAULT_LAYOUT);
    modelAndView.addObject(DEFAULT_VIEW_ATTRIBUTE_NAME, originalViewName);
}

From source file:org.cloudfoundry.identity.uaa.login.AnalyticsInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView != null && modelAndView.hasView() && analytics != null) {
        modelAndView.addObject("analytics", analytics);
    }// w ww  . ja  v  a2 s .  c o  m
}

From source file:com.orange.clara.cloud.servicedbdumper.interceptor.AddAdminUrlsInterceptor.java

public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView == null || !modelAndView.hasView() || !accessManager.isUserIsAdmin()) {
        return;//w  w  w .j  a v a 2s . c o m
    }

    Map<RequestMappingInfo, HandlerMethod> handlerMethods = this.handlerMapping.getHandlerMethods();
    this.loadMappedRequestFromRequestMappingInfoSet(handlerMethods.keySet());
    this.loadMappedRequestFromRequestMappingInfoSet(endpointHandlerMapping.getHandlerMethods().keySet());
    Collections.sort(mappedRequests, (mappedRequestInfo1, mappedRequestInfo2) -> mappedRequestInfo1.getName()
            .compareTo(mappedRequestInfo2.getName()));
    modelAndView.addObject("mappedRequests", mappedRequests);
}

From source file:com.kodgemisi.common.thymeleaf.ThymeleafLayoutInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView == null || !modelAndView.hasView()) {
        return;//from w w  w  . j  a  v  a  2s. c o  m
    }
    String originalViewName = modelAndView.getViewName();
    if (shouldDecorationAvoided(originalViewName)) {
        return;
    }

    // When using custom login page with Spring-Security, login page's controller is of type ParameterizableViewController
    // We'd better render it without any layout as it's just the login page.
    // Note that this behavior is project dependent.
    if (!(handler instanceof HandlerMethod)) {
        return;
    }

    String layoutName = getLayoutName(handler);
    modelAndView.setViewName(layoutName);
    modelAndView.addObject(this.viewAttributeName, originalViewName);
}

From source file:cherry.foundation.springmvc.OperationLogHandlerInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) {

    StringBuilder builder = createBasicInfo(request);

    if (modelAndView == null) {
        builder.append(" ModelAndView=null");
    } else if (modelAndView.hasView()) {
        builder.append(" viewName=").append(modelAndView.getViewName());
    } else {/* w  ww  . j  a  v a 2  s. c  om*/
        builder.append(" noView");
    }

    loggerMiddle.info(builder.toString());
}

From source file:org.sarons.spring4me.web.servlet.DispatcherServlet.java

@Override
protected void render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    ///*w w w.  j a v a  2s .  c  om*/
    exportContextPath(request, mv);
    //
    exportWidgetConfig(request, mv);
    //
    exportWidgetModel(request, mv);
    //
    if (mv != null && mv.hasView()) {
        //
        super.render(mv, request, response);
    }
}

From source file:fr.univrouen.poste.utils.ConfigInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {

    // we want to add usual model in modelAndView only when needed, ie with
    // direct html view :
    // not for download response (for example) because we don't need it
    // not for redirect view because we don't need it and we don't want that
    // they appears in the url

    if (modelAndView != null && modelAndView.hasView()) {

        boolean isViewObject = modelAndView.getView() == null;

        boolean isRedirectView = !isViewObject && modelAndView.getView() instanceof RedirectView;

        boolean viewNameStartsWithRedirect = isViewObject
                && modelAndView.getViewName().startsWith(UrlBasedViewResolver.REDIRECT_URL_PREFIX);

        if (!isRedirectView && !viewNameStartsWithRedirect) {

            String title = AppliConfig.getCacheTitre();
            modelAndView.addObject("title", title);

            String piedPage = AppliConfig.getCachePiedPage();
            modelAndView.addObject("piedPage", piedPage);

            String imageUrl = AppliConfig.getCacheImageUrl();
            modelAndView.addObject("imageUrl", imageUrl);

            String path = request.getServletPath();
            String subTitle = subTitles.get(path);
            String activeMenu = path.replaceAll("/", "");

            if (subTitle == null) {
                List<String> keys = new Vector<String>(subTitles.keySet());
                Collections.reverse(keys);
                for (String key : keys) {
                    if (path.startsWith(key)) {
                        subTitle = subTitles.get(key);
                        ;// w ww.j a  v a 2  s. com
                        activeMenu = key.replaceAll("/", "");
                        break;
                    }
                }
            }

            modelAndView.addObject("subTitle", subTitle);
            modelAndView.addObject("activeMenu", activeMenu);

            modelAndView.addObject("candidatCanSignup", AppliConfig.getCacheCandidatCanSignup());

            modelAndView.addObject("versionEsupDematEC", AppliVersion.getCacheVersion());

        }

        if (request.getParameter("size") != null) {
            Integer size = Integer.valueOf(request.getParameter("size"));
            request.getSession().setAttribute("size_in_session", size);
        } else if (request.getSession(false) != null
                && request.getSession().getAttribute("size_in_session") == null) {
            request.getSession().setAttribute("size_in_session", new Integer(40));
        }

    }
}

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

/**
 * Do we need view name translation?//from  www.  j a v a  2s  . c o  m
 */
private void applyDefaultViewName(HttpServletRequest request, ModelAndView mv) throws Exception {
    if (mv != null && !mv.hasView()) {
        mv.setViewName(getDefaultViewName(request));
    }
}