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:com.github.dbourdette.glass.web.interceptor.AddToModelInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView == null) {
        return;/*  w w w  .j  a va  2  s.com*/
    }

    if (StringUtils.startsWith(modelAndView.getViewName(), "redirect:")) {
        return;
    }

    ModelMap model = modelAndView.getModelMap();

    model.addAttribute("standby", quartzScheduler.isInStandbyMode());
    model.addAttribute("root", configuration.getRoot());
    model.addAttribute("current", URLEncoder.encode(request.getRequestURI(), "UTF-8"));
    model.addAttribute("utils", utilsTool);
    model.addAttribute("format", formatTool);
    model.addAttribute("version", version);
}

From source file:com.comcast.video.dawg.controller.house.StbModelControllerTest.java

@SuppressWarnings("unchecked")
@Test/*from  w  ww.java 2s  . c  o m*/
public void testModelsConfig() {
    StbModelController controller = new StbModelController();
    controller.service = new MockParkService();
    DawgModel model1 = createModel("DCT6412", "MAC_G", "HD", "DVR");
    DawgModel model2 = createModel("DCT6416", "MAC_G", "HD", "DVR", "VOD");
    DawgModel model3 = createModel("SA2200", "MAC_S");

    controller.service.upsertModel(model1, model2, model3);
    ModelAndView mav = controller.models();
    List<DawgModel> models = (List<DawgModel>) mav.getModelMap().get("models");
    Set<String> caps = (Set<String>) mav.getModelMap().get("capabilities");
    Set<String> fams = (Set<String>) mav.getModelMap().get("families");

    Assert.assertEquals(models.size(), 3);
    Assert.assertEquals(caps.size(), 3);
    Assert.assertEquals(fams.size(), 2);
    Assert.assertTrue(caps.contains("HD"));
    Assert.assertTrue(caps.contains("DVR"));
    Assert.assertTrue(caps.contains("VOD"));
    Assert.assertTrue(fams.contains("MAC_G"));
    Assert.assertTrue(fams.contains("MAC_S"));
}

From source file:com.healthcit.cacure.web.controller.QuestionListControllerTest.java

@Test
public void testShowFormsForFormWithoutQuestions() {
    Long formId = 1l;//from   w ww . java2  s  . c  o  m
    EasyMock.expect(qaManager.getAllFormQuestionsWithChildren(formId)).andReturn(new ArrayList<Question>());
    EasyMock.replay(qaManager);
    EasyMock.expect(formManager.getForm(formId)).andReturn(createMockQuestionForm(formId, 1));
    EasyMock.replay(formManager);
    ModelAndView actual = questionListController.showQuestions(1l);
    ModelAndView expected = createMockModelAndView(formId);
    Assert.assertNotNull(actual);
    Assert.assertNotNull(expected.getModelMap().get("form"));
    Assert.assertEquals(((QuestionnaireForm) expected.getModelMap().get("form")).getQuestions().size(),
            ((QuestionnaireForm) actual.getModelMap().get("form")).getQuestions().size());
}

From source file:de.hybris.platform.smarteditaddon.interceptors.beforeview.SmarteditaddonCmsPageBeforeViewHandler.java

@Override
public void beforeView(final HttpServletRequest request, final HttpServletResponse response,
        final ModelAndView modelAndView) {

    final AbstractPageModel page = (AbstractPageModel) modelAndView.getModel()
            .get(AbstractPageController.CMS_PAGE_MODEL);
    if (page != null && page.getUid() != null) {
        String presetCssClasses = (String) modelAndView.getModelMap().get(PAGE_BODY_CSS_CLASSES);

        final StringBuilder cssClasses = new StringBuilder();

        if (isNotBlank(presetCssClasses)) {
            cssClasses.append(presetCssClasses);
            cssClasses.append(' ');
        }/*from w  w w  .j  ava  2s  .  c o m*/
        cssClasses.append(CSS_CODE_PREFIX)
                .append(page.getUid().replaceAll(PAGEUID_CHARACTER_EXCLUSION_REGEXP, "-"));
        cssClasses.append(' ');

        modelAndView.addObject(PAGE_BODY_CSS_CLASSES, cssClasses.toString());
    }
}

From source file:com.healthcit.cacure.web.controller.question.FormElementListController.java

@RequestMapping(value = Constants.QUESTION_LISTING_SKIP_URI)
public ModelAndView showSkipQuestionList(@RequestParam(value = FORM_ID_NAME, required = true) Long formId,
        @RequestParam(value = "questionId", required = true) Long formElementId) {

    BaseForm form = formManager.getForm(formId);
    String viewName = "questionListSkip";

    List<BaseForm> forms = formManager.getModuleForms(form.getModule().getId());
    ModelAndView mav = new ModelAndView(viewName); // initialize with view name
    ModelMap model = mav.getModelMap();
    if (formElementId != null) {
        FormElement formElement = qaManager.getFormElement(formElementId);
        SkipAffecteesBean dependencies = qaManager.getAllPossibleSkipAffectees(formElement);
        model.addAttribute("formElementId", formElementId);
        model.addAttribute("dependencies", dependencies);
    }//from  w  ww .j  a v a2 s. c  o m

    model.addAttribute("forms", forms);

    log.debug("in QuestionListController.showSkipQuestionList(): formId: " + formId + " formElementId: "
            + formElementId);

    return mav;
}

From source file:com.carlos.projects.billing.ui.controllers.AddComponentsControllerTest.java

@Test
public void shouldAddDocumentToModel() throws Exception {
    //Given//from   w w w . j  a va  2  s . co  m
    Document expectedDocument = givenExpectedComponentsAdded();
    Map<String, String[]> parameters = givenRequestParameters();
    when(request.getParameterMap()).thenReturn(parameters);
    //When
    ModelAndView modelAndView = controller.handleRequestInternal(request, response);
    //Then
    assertThat("Model does not contain document with components added",
            (Document) modelAndView.getModelMap().get("document"), is(expectedDocument));
}

From source file:com.healthcit.cacure.web.controller.question.FormElementListController.java

/**
 * @param formId Long//from  w  w  w  .ja v  a 2 s  . com
 * @param categoryIds 
 * @param searchText 
 * @return view with form entity that fetches list of Question items
 */
private ModelAndView getModelAndView(Long formId, String searchText, long[] categoryIds) {
    BaseForm form = null;
    //      List<? extends FormElement> questions = qaManager.getAllFormElementsWithChildren(formId);
    List<FormElement> elements = qaManager.getFormElementsByTextWithinCategories(formId, searchText,
            categoryIds);

    //getting QuestionnaireForm entity
    if (!elements.isEmpty()) {
        form = elements.get(0).getForm();
        //         form.setElements(elements);
    } else {
        form = formManager.getForm(formId);
    }

    String formName = form.getName();
    String shortFormName = form.getName();
    if (shortFormName != null && shortFormName.length() > MAX_HEADER_LENGTH) {
        shortFormName = shortFormName.substring(0, MAX_HEADER_LENGTH) + "...";
    }

    ModelAndView mav = new ModelAndView("questionList"); // initialize with view name
    ModelMap model = mav.getModelMap();
    model.addAttribute(FORM_KEY, form);
    model.addAttribute("elements", elements);
    model.addAttribute("shortFormName", shortFormName);
    model.addAttribute("formName", formName);
    return mav;
}

From source file:com.healthcit.cacure.web.controller.FormListControllerTest.java

@Test
public void testShowForms() {
    EasyMock.expect(formManager.getModuleForms(1l)).andReturn(createMockQuestionForms());
    EasyMock.replay(formManager);/*from w  ww.j  a va 2  s. co  m*/
    ModelAndView expected = createMockModelAndView(1l);
    ModelAndView actual = formListController.showForms(1l);
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected.getModelMap().get("moduleId"), actual.getModelMap().get("moduleId"));
}

From source file:nl.surfnet.coin.selfservice.interceptor.AuthorityScopeInterceptor.java

@SuppressWarnings("unchecked")
@Override/*from  w w w  . j ava2 s. com*/
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {

    if (modelAndView != null) {

        List<Authority> authorities = SpringSecurity.getCurrentUser().getAuthorityEnums();

        final ModelMap map = modelAndView.getModelMap();
        scopeGeneralAuthCons(map, authorities);

        addTokenToModelMap(request, response, map);

        addSwitchIdentity(map, authorities, request);
    }
}

From source file:com.healthcit.cacure.web.interceptor.ModelAccessibilityInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    // see if a handler is of accessibility controlled type
    if (handler instanceof EditControllable && modelAndView != null) {
        EditControllable controller = (EditControllable) handler;
        if (controller.isModelEditable(modelAndView)) {

            modelAndView.getModelMap().addAttribute(Constants.IS_EDITABLE, Boolean.TRUE);
        }//ww  w  .  ja v a2  s  .  c  om
    }
}