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

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

Introduction

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

Prototype

@Nullable
public String getViewName() 

Source Link

Document

Return the view name to be resolved by the DispatcherServlet via a ViewResolver, or null if we are using a View object.

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  w w .j  av a  2s . c o m*/
                if (StringUtils.contains(viewName, "?")) {
                    modelAndView.setViewName(viewName + "&" + listQuery);
                } else {
                    modelAndView.setViewName(viewName + "?" + listQuery);
                }
            }
        }
    }
}

From source file:ar.com.zauber.commons.spring.web.controllers.ExceptionControllerTest.java

/** test */
@Test//from  w  w w.ja v  a  2 s  .  c  om
public final void test404() throws Exception {
    req.setAttribute("javax.servlet.error.status_code", 404);
    final ModelAndView mav = exceptionController.handleRequestInternal(req, res);
    Assert.assertEquals("exceptions/notfound", mav.getViewName());
}

From source file:edu.wisc.doit.tcrypt.CreateControllerTest.java

@Test
public void testInitReturnsCorrectView() throws Exception {
    ModelAndView handleRequest = createController.createServiceKeyInit();
    assertEquals(handleRequest.getViewName(), "createServiceKeyBefore");
}

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

@Test
public void shouldImportDataAndPutNumberOfImportedItemsInTheModelWhenOnSubmit() throws Exception {
    //given//from   w  w w  .  java2s  .co m
    ImportComponentsController controller = new ImportComponentsController(importer, componentDAO);
    List<Component> components = createComponents();
    Map<String, Object> expectedModel = mockExpectedModel(components);
    when(command.getFile()).thenReturn(file);
    when(importer.importData(file)).thenReturn(2L);
    when(componentDAO.findAll("Component")).thenReturn(components);

    //when
    ModelAndView mav = controller.onSubmit(command);

    //then
    assertThat(mav.getViewName(), is("showComponents"));
    assertThat(mav.getModel(), is(expectedModel));
}

From source file:fm.last.citrine.web.DisplayLogsControllerTest.java

@Test
public void testNoLoList() throws Exception {
    List<String> logFiles = new ArrayList<String>();
    logFiles.add("log1.log");
    logFiles.add("log2.log");
    when(mockLogFileManager.findAllLogFiles()).thenReturn(logFiles);
    ModelAndView modelAndView = displayLogsController.list(mockRequest, mockResponse);
    assertEquals("logs_list", modelAndView.getViewName());
    Map<String, Object> model = modelAndView.getModel();
    assertEquals(1, model.size());// w w w  .  j  a  v  a2s.  co m
    assertEquals(logFiles, model.get("logFiles"));
}

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);
                }//  w w  w .  j  av  a 2  s  . c  o  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:gov.nih.nci.cabig.caaers.web.admin.ImportMeddraController.java

public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    setViewName("admin/meddra_import");
    ModelAndView mav = new ModelAndView("admin/meddra_import");
    mav.addObject("meddraVersions", meddraVersionDao.getAll());
    log.debug("modelAndView" + mav.getViewName());

    return mav;/*from www  . ja v  a2  s.  c  o  m*/
}

From source file:nl.surfnet.coin.selfservice.control.HomeControllerTest.java

@Test
public void testIdp() throws Exception {
    Collection<SabPerson> maintainers = Collections.emptyList();
    when(sabClient.getPersonsInRoleForOrganization(institutionIdentityProvider.getInstitutionId(),
            "SURFconextbeheerder")).thenReturn(maintainers);
    Collection<SabPerson> responsibles = Collections.emptyList();
    when(sabClient.getPersonsInRoleForOrganization(institutionIdentityProvider.getInstitutionId(),
            "SURFconextverantwoordelijke")).thenReturn(responsibles);

    ModelAndView modelAndView = controller.idp(request);

    assertEquals("idp", modelAndView.getViewName());
    assertTrue(modelAndView.getModel().containsKey("roleAssignments"));
}

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 w w.j a  v a 2 s .c  om
    }
    String originalViewName = modelAndView.getViewName();
    modelAndView.addObject("title");
    modelAndView.setViewName(DEFAULT_LAYOUT);
    modelAndView.addObject(DEFAULT_VIEW_ATTRIBUTE_NAME, originalViewName);
}

From source file:ar.com.zauber.commons.spring.web.controllers.ExceptionControllerTest.java

/** test */
@Test// w  w w .ja v a  2  s  . co m
public final void test500() throws Exception {
    req.setAttribute("javax.servlet.error.status_code", 500);
    final ModelAndView mav = exceptionController.handleRequestInternal(req, res);
    Assert.assertEquals("exceptions/internalerror", mav.getViewName());
}