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.ari.controller.catalog.CategoryController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView model = super.handleRequest(request, response);

    Category category = (Category) model.getModel().get("category");

    if (request.getRequestURI().equals("/")) {
        category = (Category) model.getModelMap().get("category");
        String url = category.getChildCategories().get(0).getUrl();
        //  .//  ww w.  j ava  2 s  . c  o m
        RedirectView rv = new RedirectView(url);
        rv.setExposeModelAttributes(true);

        return new ModelAndView(rv);
    }

    //?  ? category .
    //TODO  .
    if (false == request.getParameterMap().containsKey("facetField")) {
        //            List<SortOption> sortOptions = ((ExCategoryImpl) model.getModelMap().get(CATEGORY_ATTRIBUTE_NAME)).getSortOptions();
        //            for(SortOption sortOption : sortOptions){
        //                String sortCondition = sortOption.getSortCondition();
        //                sortOption.setLink(addSortLink(sortOption));
        //            }
    }

    //? ?   
    CategoryAttribute categoryType = category.getCategoryAttributesMap().get("CategoryType");
    if (categoryType != null) {
        String categoryTypeValue = categoryType.getValue();

        if (categoryTypeValue.equals("main") && null != request.getParameter("page")) {
            model.setViewName("/ari/layout/partials/productList");
        }
    }

    return model;
}

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

@SuppressWarnings("unchecked")
@RequestMapping(value = Constants.XFORM_PREVIEW_URI, method = RequestMethod.POST)
public ModelAndView processXForm(HttpServletRequest request, HttpServletResponse response) {
    ModelAndView map = new ModelAndView();
    String xformContent = org.apache.commons.lang.StringUtils.defaultIfEmpty(IOUtils.read(request),
            "No content available");
    String escapedXformContent = StringEscapeUtils.escapeHtml(xformContent);
    map.getModelMap().put(XFORM_BODY, escapedXformContent);
    map.getModelMap().put(XFORM_MODEL, MODEL_START_TAG + ">" + xformContent + MODEL_END_TAG);
    map.getModelMap().put(XFORM_TITLE, "SUBMISSION SUCCESSFUL");
    map.setViewName(XFORM_PREVIEW_VIEW);
    return map;/*  w  w w  . ja v  a  2s.  c om*/
}

From source file:org.jasig.cas.services.web.ManageRegisteredServicesMultiActionControllerTests.java

public void testDeleteService() {
    final RegisteredServiceImpl r = new RegisteredServiceImpl();
    r.setId(1200);//from  w ww  .j ava  2s  .com
    r.setName("name");
    r.setServiceId("serviceId");
    r.setEvaluationOrder(1);

    this.servicesManager.save(r);

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("id", "1200");

    final ModelAndView modelAndView = this.controller.deleteRegisteredService(request,
            new MockHttpServletResponse());

    assertNotNull(modelAndView);
    assertNull(this.servicesManager.findServiceBy(1200));
    assertEquals("deleted", modelAndView.getModel().get("status"));
    assertEquals("name", modelAndView.getModelMap().get("serviceName"));
}

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

@Test
public void shouldForwardToNewDocumentPageWithComponentsDocumentIdAndFamilyInModel() throws Exception {
    // Given/*from w ww .  j a va2  s .c  o  m*/
    controller.setViewName("selectComponents");

    String familyNameValue = "familyNameValue";
    Long documentIdValue = 12345L;

    String componentId1 = "componentId1";
    Component component1 = createComponent(componentId1);
    String componentId2 = "componentId2";
    Component component2 = createComponent(componentId2);

    Map<String, String[]> parameters = new HashMap<String, String[]>();
    parameters.put("componentId1", new String[] { "valueComponentId1" });
    parameters.put("componentId2", new String[] { "valueComponentId2" });
    parameters.put("familyName", new String[] { familyNameValue });
    parameters.put("documentId", new String[] { documentIdValue.toString() });

    when(request.getParameterMap()).thenReturn(parameters);
    when(request.getParameter("familyName")).thenReturn(familyNameValue);
    when(request.getParameter("documentId")).thenReturn(documentIdValue.toString());
    when(componentDAO.getById(Component.class, componentId1)).thenReturn(component1);
    when(componentDAO.getById(Component.class, componentId2)).thenReturn(component2);

    // When
    ModelAndView modelAndView = controller.handleRequest(request, response);

    // Then
    assertThat("The view name is wrong", modelAndView.getViewName(), is("selectComponents"));
    assertThat("The size of the list is wrong",
            ((List<Component>) modelAndView.getModelMap().get("components")).size(), is(2));
    assertThat("The list of components is wrong",
            (List<Component>) modelAndView.getModelMap().get("components"), hasItems(component1, component2));
    assertThat("The family name is wrong", (String) modelAndView.getModelMap().get("familyName"),
            is(familyNameValue));
    assertThat("The document id is wrong", (Long) modelAndView.getModelMap().get("documentId"),
            is(documentIdValue));
}

From source file:de.hybris.platform.b2bpunchoutaddon.interceptors.PunchOutBeforeViewHandler.java

@Override
public void beforeView(final HttpServletRequest request, final HttpServletResponse response,
        final ModelAndView modelAndView) throws PunchOutException {
    final String viewName = modelAndView.getViewName();
    try {//from   w  w  w  . j ava2s.  c om
        if (StringUtils.isNotBlank(
                (String) request.getSession().getAttribute(B2bpunchoutaddonConstants.PUNCHOUT_USER))) {
            modelAndView.setViewName(getPunchoutView(viewName));
            setPunchoutModeInModel(modelAndView.getModelMap());
        }
    } catch (final Exception e) {
        throw new PunchOutException(PunchOutResponseCode.INTERNAL_SERVER_ERROR, e.getMessage(), e);
    }
}

From source file:com.sandboxnine.controller.catalog.CategoryController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView model = super.handleRequest(request, response);

    //?  ? category .
    //TODO  .//  w w w . j  av a2s. com
    if (false == request.getParameterMap().containsKey("facetField")) {
        List<SortOption> sortOptions = ((ExCategoryImpl) model.getModelMap().get(CATEGORY_ATTRIBUTE_NAME))
                .getSortOptions();
        for (SortOption sortOption : sortOptions) {
            String sortCondition = sortOption.getSortCondition();
            sortOption.setLink(addSortLink(sortOption));
        }
    }

    return model;
}

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

@Test
public void token_session_does_not_equal_request_param_token() throws Exception {
    ModelAndView modelAndView = buildSecurityContext(ROLE_DASHBOARD_ADMIN);

    MockHttpServletRequest request = new MockHttpServletRequest();
    interceptor.postHandle(request, null, null, modelAndView);

    // first check if the token is generated and stored in session and modelMap
    String token = (String) modelAndView.getModelMap().get(TOKEN_CHECK);
    assertNotNull(token);/*from   ww w  . ja  va  2 s  .c  om*/

    String sessionToken = (String) request.getSession(false).getAttribute(TOKEN_CHECK);
    assertNotNull(token);
    assertEquals(token, sessionToken);

    // now check if the prehandle checks the token if the method is a POST
    request = new MockHttpServletRequest();
    request.setMethod(RequestMethod.POST.name());
    try {
        interceptor.preHandle(request, null, null);
        fail("Expected security exception");
    } catch (Exception e) {
    }

    // now check if the prehandle checks the token if the method is a POST
    request = new MockHttpServletRequest();
    request.addParameter(TOKEN_CHECK, sessionToken);
    request.getSession().setAttribute(TOKEN_CHECK, sessionToken);
    request.setMethod(RequestMethod.POST.name());

    assertTrue(interceptor.preHandle(request, null, null));

}

From source file:com.tms.controller.customer.CustomerController.java

@RequestMapping("/list")
public ModelAndView customerList(String searchStr, String order, String sort, HttpServletResponse response,
        HttpServletRequest request) throws Exception {
    ModelAndView view = new ModelAndView();
    List<Company> list = companyService.findAll();
    view.getModelMap().put("customers", list);
    view.setViewName("admin/customer/customerlist");
    return view;/* w w w  .  j av a 2  s . c om*/
}

From source file:com.tms.controller.customer.CustomerController.java

@RequestMapping("/list_nd")
public ModelAndView customerListValue(HttpServletResponse response, HttpServletRequest request)
        throws Exception {
    ModelAndView view = new ModelAndView();
    List<Company> list = companyService.findAll();
    view.getModelMap().put("customers", list);
    view.setViewName("admin/customer/customerlisttable");
    return view;/*from  w w  w  .ja v  a  2  s . c  o m*/
}

From source file:fragment.web.AbstractBaseControllerTest.java

@Test
public void testHandleAccessDeniedException() {
    AccessDeniedException ex = new AccessDeniedException("test");
    ModelAndView mav = controller.handleAccessDeniedException(ex, new MockHttpServletRequest());
    Assert.assertNotNull(mav.getModelMap());
    ModelAndViewAssert.assertViewName(mav, "errors/notauthorized");
}