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

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

Introduction

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

Prototype

public ModelMap getModelMap() 

Source Link

Document

Return the underlying ModelMap instance (never null ).

Usage

From source file:org.beadle.framework.view.ReturnTypeViewResolver.java

private View getBestView(List<View> candidateViews, List<MediaType> requestedMediaTypes,
        RequestAttributes attrs) {//from  ww  w . j a v a  2  s  .  c  o m
    HttpServletRequest request = ((ServletRequestAttributes) attrs).getRequest();
    for (View candidateView : candidateViews) {
        if (StringUtils.hasText(candidateView.getContentType())) {
            ModelAndView mv = (ModelAndView) request.getAttribute("ModelAndView");
            //message...
            Object result = mv.getModelMap().get("message");
            MediaType candidateContentType = MediaType.parseMediaType(candidateView.getContentType());
            if (result == null && candidateContentType.isCompatibleWith(MediaType.TEXT_HTML)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Returning [" + candidateView + "] based on requested media type '"
                            + candidateContentType + "'");
                }
                attrs.setAttribute(View.SELECTED_CONTENT_TYPE, candidateContentType,
                        RequestAttributes.SCOPE_REQUEST);
                return candidateView;
            } else if (result != null && candidateContentType.isCompatibleWith(MediaType.APPLICATION_JSON)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Returning [" + candidateView + "] based on requested media type '"
                            + candidateContentType + "'");
                }
                attrs.setAttribute(View.SELECTED_CONTENT_TYPE, candidateContentType,
                        RequestAttributes.SCOPE_REQUEST);
                return candidateView;
            }
        }
    }
    return null;
}

From source file:org.egov.infra.web.spring.interceptor.DuplicateFormSubmissionInterceptor.java

private static BindingResult getBindingResult(final ModelAndView modelAndView) {
    final Set<String> paramNames = modelAndView.getModelMap().keySet();
    return (BindingResult) modelAndView.getModelMap().get(paramNames.parallelStream()
            .filter(e -> e.startsWith(BindingResult.MODEL_KEY_PREFIX)).findFirst().get());
}

From source file:org.hoteia.qalingo.core.web.mvc.interceptor.PageModelDataHandlerInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    try {//from  w ww.ja v a  2 s . c o m
        final RequestData requestData = requestUtil.getRequestData(request);
        final GeolocData geolocData = requestData.getGeolocData();
        final MarketPlace currentMarketPlace = requestData.getMarketPlace();
        final MarketArea currentMarketArea = requestData.getMarketArea();
        final Localization currentLocalization = requestData.getMarketAreaLocalization();
        final Locale locale = requestData.getLocale();
        final Customer customer = requestData.getCustomer();
        final String currentUrl = requestUtil.getCurrentRequestUrl(request);

        if (modelAndView != null) {
            String requestParamMinifyAssets = request.getParameter("minifyAssets");
            if (StringUtils.isNotEmpty(requestParamMinifyAssets)) {
                request.getSession().setAttribute("minifyAssets", requestParamMinifyAssets);
            }
            String sessionMinifyAssets = (String) request.getSession().getAttribute("minifyAssets");
            if (StringUtils.isNotEmpty(sessionMinifyAssets)) {
                modelAndView.getModelMap().put("minifyAssets", BooleanUtils.toBoolean(sessionMinifyAssets));
            } else {
                modelAndView.getModelMap().put("minifyAssets", minifyAssets);
            }

            modelAndView.getModelMap().put("assetsVersion", assetsVersion);

            // SANITY CHECK : Controle MarketArea
            String referer = request.getHeader(Constants.REFERER);

            if (StringUtils.isEmpty(referer) || !referer.contains("coloroptical.com")) {
                // VISITOR COME FROM OTHER WEBSITE : check the target
                if (geolocData != null && geolocData.getCountry() != null && currentMarketArea != null
                        && StringUtils.isNotEmpty(geolocData.getCountry().getIsoCode()) && !geolocData
                                .getCountry().getIsoCode().equals(currentMarketArea.getGeolocCountryCode())) {
                    // TARGET IS NOT THE GEOLOCATED MARKET AREA
                    String targetUrl = request.getRequestURI().replace(request.getContextPath(), "");

                    //                     System.out.println("need redirect modal");
                    //                     System.out.println("targetUrl: " + targetUrl);

                    MarketArea marketAreaGeoloc = null;
                    List<MarketArea> marketAreas = marketService
                            .findMarketAreaOpenedByGeolocCountryCode(geolocData.getCountry().getIsoCode());
                    if (marketAreas != null) {
                        if (marketAreas.size() == 1) {
                            marketAreaGeoloc = marketAreas.get(0);
                        } else {
                            // WE HAVE MANY MARKET AREA FOR THE CURRENT COUNTRY CODE - WE SELECT THE DEFAULT MARKET PLACE ASSOCIATE
                            for (MarketArea marketAreaIt : marketAreas) {
                                if (marketAreaIt.getMarket().getMarketPlace().isDefault()) {
                                    marketAreaGeoloc = marketAreaIt;
                                }
                            }
                        }

                        String context = "/" + marketAreaGeoloc.getCode() + "/"
                                + marketAreaGeoloc.getDefaultLocalization().getCode() + "/";
                        String newSegmentl = urlService
                                .getSeoSegmentMain(marketAreaGeoloc.getDefaultLocalization().getLocale(), true);
                        String[] splits = request.getRequestURI().split("/");
                        String target = "";
                        int count = 0;
                        for (String split : splits) {
                            if (count == (splits.length - 1)) {
                                target = split;
                            }
                            count++;
                        }

                        String newUrl = context.toLowerCase() + newSegmentl + "/" + target;
                        String newAbsoluteUrl = urlService.buildAbsoluteUrl(requestData, newUrl);
                        logger.debug("Redirect to: " + newAbsoluteUrl);

                        try {
                            // TEST TARGET URL
                            URL obj = new URL(newAbsoluteUrl);
                            HttpURLConnection con = (HttpURLConnection) obj.openConnection();
                            con.setRequestMethod("GET");
                            con.setRequestProperty("User-Agent", request.getHeader("User-Agent"));
                            int responseCode = con.getResponseCode();
                            if (responseCode != 200) {
                                logger.debug("Url is not OK/200, url: " + newAbsoluteUrl);
                                MarketAreaViewBean marketAreaGeolocViewBean = frontofficeViewBeanFactory
                                        .buildViewBeanMarketArea(requestData, currentMarketArea);
                                newAbsoluteUrl = urlService.buildAbsoluteUrl(requestData,
                                        marketAreaGeolocViewBean.getChangeContextUrl());
                                logger.debug("Switch URL target, new url: " + newAbsoluteUrl);
                            }

                        } catch (Exception e) {
                            // TODO: handle exception
                        }

                        modelAndView.getModelMap().put("newAbsoluteUrl", newAbsoluteUrl);
                        modelAndView.getModelMap().put("redirectMarketArea", true);
                        modelAndView.getModelMap().put("redirectMarketAreaCountry", referentialDataService
                                .getCountryByLocale(geolocData.getCountry().getIsoCode(), locale));
                        modelAndView.getModelMap().put("targetMarketAreaCountry", referentialDataService
                                .getCountryByLocale(currentMarketArea.getGeolocCountryCode(), locale));

                    } else {
                        logger.debug("There is no MarketArea for this country:"
                                + geolocData.getCountry().getIsoCode());

                    }
                }
            }

            boolean displayHttpsNavBarMessage = false;
            if (currentUrl.contains("login")) {
                displayHttpsNavBarMessage = true;
            }
            Cookie[] cookies = request.getCookies();
            if (cookies != null) {
                Cookie navBarMessageCookie = null;
                boolean found = false;
                String navBarMessageName = cookiePrefix + "_NAV_BAR_MESSAGE";
                for (Cookie cookie : cookies) {
                    if (navBarMessageName.equals(cookie.getName())) {
                        navBarMessageCookie = cookie;
                        found = true;
                        break;
                    }
                }
                if (found && navBarMessageCookie.getValue().equals("hide")) {
                    displayHttpsNavBarMessage = false;
                }
            }
            modelAndView.getModelMap().put("displayHttpsNavBarMessage", displayHttpsNavBarMessage);

            if (geolocData != null && geolocData.getCity() != null
                    && StringUtils.isNotEmpty(geolocData.getCity().getName())) {
                modelAndView.getModelMap().addAttribute("cityName", geolocData.getCity().getName());
                modelAndView.getModelMap().addAttribute("isGeolocated", true);
            }

            modelAndView.getModelMap().put(ModelConstants.LEGAl_TERMS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildViewBeanLegalTerms(requestData));

            modelAndView.getModelMap().put(ModelConstants.HEADER_CART,
                    frontofficeViewBeanFactory.buildViewBeanHeaderCart(requestData));

            // MARKETS FOR THE CURRENT MARKETPLACE
            Set<Market> marketList = currentMarketPlace.getMarkets();
            List<MarketAreaViewBean> allMarketAreaViewBeans = new ArrayList<MarketAreaViewBean>();
            for (Market market : marketList) {
                Set<MarketArea> marketAreaList = market.getMarketAreas();
                for (MarketArea marketArea : marketAreaList) {
                    if (marketArea.isOpened()) {
                        MarketArea reloadedMarketArea = marketService.getMarketAreaById(marketArea.getId());
                        MarketAreaViewBean marketAreaViewBean = frontofficeViewBeanFactory
                                .buildViewBeanMarketArea(requestData, reloadedMarketArea);
                        if (currentMarketArea.getId().equals(reloadedMarketArea.getId())) {
                            marketAreaViewBean.setActive(true);
                        }
                        allMarketAreaViewBeans.add(marketAreaViewBean);
                    }
                }
            }

            // MARKET AREAS FOR THE CURRENT MARKET
            modelAndView.getModelMap().put(ModelConstants.MARKET_AREAS_VIEW_BEAN, allMarketAreaViewBeans);

            // CURRENT MARKET AREA
            modelAndView.getModelMap().put(ModelConstants.MARKET_AREA_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildViewBeanMarketArea(requestData, currentMarketArea));

            // LOCALIZATIONS FOR THE CURRENT MARKET AREA
            modelAndView.getModelMap().put("marketAreaLocalization",
                    frontofficeViewBeanFactory.buildViewBeanLocalization(requestData, currentLocalization));
            modelAndView.getModelMap().put(ModelConstants.MARKET_AREA_LANGUAGES_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanLocalizationByMarketArea(requestData,
                            currentLocalization));

            // RETAILERS FOR THE CURRENT MARKET AREA
            modelAndView.getModelMap().put(ModelConstants.MARKET_AREA_RETAILERS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanRetailerByMarketArea(requestData));

            // CURRENCIES FOR THE CURRENT MARKET AREA
            modelAndView.getModelMap().put(ModelConstants.MARKET_AREA_CURRENCIES_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanCurrenciesByMarketArea(requestData));

            // HEADER
            modelAndView.getModelMap().put(ModelConstants.HEADER_NAVS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanHeaderNav(requestData));
            modelAndView.getModelMap().put(ModelConstants.HEADER_MENUS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanCmsMenus(requestData));

            // FOOTER
            modelAndView.getModelMap().put(ModelConstants.FOOTER_MENUS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanFooterMenu(requestData));
            modelAndView.getModelMap().put(ModelConstants.FOOTER_NAVS_VIEW_BEAN,
                    frontofficeViewBeanFactory.buildListViewBeanFooterNav(requestData));

            //TODO a remonter dans CommonViewBean
            modelAndView.getModelMap().put("checkoutShoppingCartUrl",
                    urlService.generateUrl(FoUrls.CART_DETAILS, requestData));

            final List<Long> lastCmsContentIds = cmsContentService.findLastActiveCmsContentIds(
                    CmsContent.APP_NAME_FRONTOFFICE_B2C, "ARTICLE", currentMarketArea.getId(),
                    currentLocalization.getId(), 20);
            final List<CmsContent> reloadedCmsContents = new ArrayList<CmsContent>();
            final Date now = new Date();
            for (Iterator<Long> iterator = lastCmsContentIds.iterator(); iterator.hasNext();) {
                Long cmsContentId = (Long) iterator.next();
                if (reloadedCmsContents.size() == 9) {
                    // WE HAVE LOAD 20 items WITHOUT PARAM PUBLISH DATE, WE FILTER AFTER 
                    // TODO : specific query to load 9 items already publish and active
                    break;
                }
                CmsContent reloadedCmsContent = cmsContentService.getCmsContentById(cmsContentId);
                if (reloadedCmsContent.getDatePublish().getTime() < now.getTime()) {
                    reloadedCmsContents.add(reloadedCmsContent);
                }
            }
            final List<CmsContentViewBean> cmsContentViewBeans = frontofficeViewBeanFactory
                    .buildListViewBeanCmsContent(requestData, reloadedCmsContents);
            if (cmsContentViewBeans != null && !cmsContentViewBeans.isEmpty()) {
                modelAndView.getModelMap().put("footerLastArticles", cmsContentViewBeans);
            }
            modelAndView.getModelMap().put("allArticleUrl",
                    urlService.generateUrl(FoUrls.ARTICLES, requestData));

            // GEOLOC
            //                if(requestData.getGeolocData() != null){
            //                    modelAndView.getModelMap().put(ModelConstants.GEOLOC_REMOTE_ADDRESS, requestData.getGeolocData().getRemoteAddress());
            //                    modelAndView.getModelMap().put(ModelConstants.GEOLOC_COUNTRY, requestData.getGeolocData().getCountry());
            //                    modelAndView.getModelMap().put(ModelConstants.GEOLOC_CITY, requestData.getGeolocData().getCity());
            //                }

            // APP NAME
            modelAndView.getModelMap().addAttribute(Constants.APP_NAME, requestUtil.getAppName(request));
            Object[] appNameParams = { StringUtils.capitalize(requestUtil.getApplicationName()) };
            modelAndView.getModelMap().addAttribute(Constants.APP_NAME_HTML, coreMessageSource.getCommonMessage(
                    ScopeCommonMessage.APP.getPropertyKey(), "name_html", appNameParams, locale));

            modelAndView.getModelMap().addAttribute(ModelConstants.LOCALE_LANGUAGE_CODE, locale.getLanguage());
            modelAndView.getModelMap().addAttribute(ModelConstants.CONTEXT_PATH, request.getContextPath());
            modelAndView.getModelMap().addAttribute(ModelConstants.THEME, requestUtil.getCurrentTheme(request));
            Object[] params = { StringUtils.capitalize(requestUtil.getEnvironmentName()) };
            modelAndView.getModelMap().addAttribute(ModelConstants.ENV_NAME,
                    coreMessageSource.getSpecificMessage(I18nKeyValueUniverse.FO.getPropertyKey(),
                            ScopeWebMessage.COMMON.getPropertyKey(), "header.env.name", params, locale));

            if (!modelAndView.getModelMap().containsAttribute(ModelConstants.SEO_DATA_VIEW_BEAN)) {
                SeoDataViewBean seoData = frontofficeViewBeanFactory.buildViewSeoData(requestData);
                if (modelAndView.getModelMap().containsAttribute(ModelConstants.PAGE_TITLE)) {
                    String pageTitle = (String) modelAndView.getModelMap().get(ModelConstants.PAGE_TITLE);
                    seoData.setMetaOgTitle(pageTitle);
                    seoData.setPageTitle(pageTitle);
                }
                modelAndView.getModelMap().put(ModelConstants.SEO_DATA_VIEW_BEAN, seoData);
            }

            modelAndView.getModelMap().put(ModelConstants.URL_SUBMIT_QUICK_SEARCH,
                    urlService.generateUrl(FoUrls.CATALOG_SEARCH, requestUtil.getRequestData(request)));

            String currentRequestUrl = requestUtil.getCurrentRequestUrl(request);
            if (modelAndView.getModelMap().get(ModelConstants.ALTERNATE_LINKS_VIEW_BEAN) == null) {
                System.out.println("!!!!! THIS URL NEED AN alternate: " + currentRequestUrl);
            }
            //              // Alternate Links
            //              if(modelAndView.getModelMap().get(ExtModelConstants.ALTERNATE_LINKS_VIEW_BEAN) == null){
            //                  String currentRequestUrl = requestUtil.getCurrentRequestUrl(request);
            //                  List<HeadLinkViewBean> alternateLinks = new ArrayList<HeadLinkViewBean>();
            //                  if(currentRequestUrl.contains("article")){
            //                     
            //                  } else {
            //                     // default
            //                      for (MarketAreaViewBean marketAreaViewBean : allMarketAreaViewBeans) {
            //                         for (LocalizationViewBean localizationViewBean : marketAreaViewBean.getLocalizations()) {
            //                             if(!marketAreaViewBean.getCode().equals(currentMarketArea.getCode())){
            //                                String splitUrl[] = currentRequestUrl.split("/");
            //                                String alternateUrl = "/" + marketAreaViewBean.getCode().toLowerCase() + "/" + localizationViewBean.getCode();
            //                                for (int i = 3; i < splitUrl.length; i++) {
            //                               alternateUrl = alternateUrl + "/" + splitUrl[i];
            //                            }
            //                                String hreflang = localizationViewBean.getLocaleCode().replace("_", "-");
            //                                if(marketAreaViewBean.getCode().equals("INT") && localizationViewBean.getCode().equals("en")){
            //                                   hreflang = "x-default";
            //                                }
            //                                 HeadLinkViewBean metaLink = new HeadLinkViewBean("alternate", hreflang, alternateUrl);
            //                                alternateLinks.add(metaLink);
            //                             }
            //                         }
            //                    }
            //                  }
            //                  if(!alternateLinks.isEmpty()){
            //                      modelAndView.getModelMap().addAttribute("alternateLinks", alternateLinks);
            //                  }
            //              }

        }

    } catch (Exception e) {
        logger.error("Inject common datas failed", e);
    }

}

From source file:org.hoteia.qalingo.web.mvc.controller.catalog.ProductController.java

/**
 * /*w  w w. j  av  a  2 s.  co m*/
 */
protected void initSpecificSeo(final HttpServletRequest request, final ModelAndView modelAndView,
        final String titleKeyPrefixSufix, String productName) throws Exception {
    final RequestData requestData = requestUtil.getRequestData(request);
    final Locale locale = requestData.getLocale();

    String pageTitleKey = "header.title." + titleKeyPrefixSufix;
    String appName = (String) modelAndView.getModelMap().get(Constants.APP_NAME);
    Object[] params = { productName };
    String headerTitle = coreMessageSource.getMessage(pageTitleKey, params, locale);
    modelAndView.addObject(ModelConstants.SEO_PAGE_META_TITLE, appName + " - " + headerTitle);
    modelAndView.addObject(ModelConstants.MAIN_CONTENT_TITLE, headerTitle);
}

From source file:org.kuali.rice.krad.uif.util.UifWebUtils.java

/**
 * After the controller logic is executed, the form is placed into session
 * and the corresponding view is prepared for rendering
 */// w w w.  j  a  v a  2 s  .c o  m
public static void postControllerHandle(HttpServletRequest request, HttpServletResponse response,
        Object handler, ModelAndView modelAndView) throws Exception {
    if (handler instanceof UifControllerBase && (modelAndView != null)) {
        UifControllerBase controller = (UifControllerBase) handler;
        UifFormBase form = null;

        // check to see if this is a full view request
        if (modelAndView.getViewName().equals(UifConstants.SPRING_VIEW_ID)) {
            Object model = modelAndView.getModelMap().get(UifConstants.DEFAULT_MODEL_NAME);
            if (model instanceof UifFormBase) {
                form = (UifFormBase) model;

                // prepare view instance
                prepareViewForRendering(request, form);

                // update history for view
                prepareHistory(request, form);
            }
        }
    }
}

From source file:org.kuali.rice.krad.web.controller.UifControllerBase.java

/**
 * Configures the <code>ModelAndView</code> instance containing the form data and pointing to the UIF
 * generic spring view, additional attributes may be exposed to the view through the map argument
 *
 * @param form form instance containing the model data
 * @param additionalViewAttributes map of additional attributes to expose, key will be string the object
 * is exposed under//from ww w  . j ava2  s .c  o  m
 * @return ModelAndView object with the contained form
 */
protected ModelAndView getUIFModelAndView(UifFormBase form, Map<String, Object> additionalViewAttributes) {
    ModelAndView modelAndView = UifControllerHelper.getUIFModelAndView(form, form.getPageId());

    if (additionalViewAttributes != null) {
        for (Map.Entry<String, Object> additionalViewAttribute : additionalViewAttributes.entrySet()) {
            modelAndView.getModelMap().put(additionalViewAttribute.getKey(),
                    additionalViewAttribute.getValue());
        }
    }

    return modelAndView;
}

From source file:org.kuali.rice.krad.web.controller.UifControllerHandlerInterceptor.java

/**
 * After the controller logic is executed, the form is placed into session and the corresponding view
 * is prepared for rendering.// w  w  w  . java  2s  . c  o m
 *
 * {@inheritDoc}
 */
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (request.getAttribute(UifParameters.Attributes.VIEW_LIFECYCLE_COMPLETE) == null) {
        getModelAndViewService().prepareView(request, modelAndView);
    }

    if ((modelAndView != null) && (modelAndView.getModelMap() != null)) {
        Object model = modelAndView.getModelMap().get(UifConstants.DEFAULT_MODEL_NAME);
        if ((model != null) && (model instanceof ViewModel)) {
            ((ViewModel) model).preRender(request);
        }
    }

    ProcessLogger.trace("post-handle");
}

From source file:org.kuali.rice.krad.web.controller.UifControllerHelper.java

/**
 * After the controller logic is executed, the form is placed into session
 * and the corresponding view is prepared for rendering
 *
 * @param request servlet request/*from  w  w w .ja va2s .c  om*/
 * @param response servlet response
 * @param handler handler instance
 * @param modelAndView model and view
 * @throws Exception
 */
public static void postControllerHandle(HttpServletRequest request, HttpServletResponse response,
        Object handler, ModelAndView modelAndView) throws Exception {
    if (modelAndView == null) {
        return;
    }

    Object model = modelAndView.getModelMap().get(UifConstants.DEFAULT_MODEL_NAME);
    if (!(model instanceof UifFormBase)) {
        return;
    }

    UifFormBase form = (UifFormBase) model;

    if (!form.isRequestRedirected()) {
        prepareViewForRendering(request, response, form);
    }

    // expose additional objects to the templates
    modelAndView.addObject(UifParameters.REQUEST, request);
    modelAndView.addObject(KRADConstants.USER_SESSION_KEY,
            request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY));

    Map<String, String> properties = CoreApiServiceLocator.getKualiConfigurationService().getAllProperties();
    modelAndView.addObject(UifParameters.CONFIG_PROPERTIES, properties);

    modelAndView.addObject(UifParameters.RENDER_HELPER_METHODS, new UifRenderHelperMethods());
}

From source file:org.kuali.rice.krad.web.service.impl.ModelAndViewServiceImpl.java

/**
 * {@inheritDoc}//w w w .  j  a  v  a  2  s  .  c o m
 */
@Override
public ModelAndView getModelAndView(UifFormBase form, Map<String, Object> additionalViewAttributes) {
    ModelAndView modelAndView = getModelAndView(form, form.getPageId());

    if (additionalViewAttributes != null) {
        for (Map.Entry<String, Object> additionalViewAttribute : additionalViewAttributes.entrySet()) {
            modelAndView.getModelMap().put(additionalViewAttribute.getKey(),
                    additionalViewAttribute.getValue());
        }
    }

    return modelAndView;
}

From source file:org.kuali.rice.krad.web.service.impl.ModelAndViewServiceImpl.java

/**
 * {@inheritDoc}/*from ww  w.java 2 s.c o  m*/
 */
@Override
public void prepareView(HttpServletRequest request, ModelAndView modelAndView) {
    if (modelAndView == null) {
        return;
    }

    Object model = modelAndView.getModelMap().get(UifConstants.DEFAULT_MODEL_NAME);
    if (!(model instanceof UifFormBase)) {
        return;
    }

    UifFormBase form = (UifFormBase) model;

    if (!form.isRequestRedirected()) {
        invokeViewLifecycle(request, form);
    }

    // expose additional objects to the templates
    modelAndView.addObject(UifParameters.REQUEST, request);
    modelAndView.addObject(KRADConstants.USER_SESSION_KEY,
            request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY));

    Map<String, String> properties = CoreApiServiceLocator.getKualiConfigurationService().getAllProperties();
    modelAndView.addObject(UifParameters.CONFIG_PROPERTIES, properties);

    modelAndView.addObject(UifParameters.RENDER_HELPER_METHODS, new UifRenderHelperMethods());
}