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

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

Introduction

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

Prototype

public void setView(@Nullable View view) 

Source Link

Document

Set a View object for this ModelAndView.

Usage

From source file:cherry.sqlapp.controller.login.LoginControllerImpl.java

@Override
public ModelAndView loginFailed(Locale locale, SitePreference sitePref, HttpServletRequest request,
        RedirectAttributes redirAttr) {//from  ww w  .  j  a v  a2  s. com

    redirAttr.addFlashAttribute(PathDef.METHOD_LOGIN_FAILED, true);

    UriComponents uc = fromMethodCall(on(LoginController.class).init(locale, sitePref, request)).build();

    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView(uc.toUriString(), true));
    return mav;
}

From source file:cherry.sqlapp.controller.login.LoginControllerImpl.java

@Override
public ModelAndView loggedOut(Locale locale, SitePreference sitePref, HttpServletRequest request,
        RedirectAttributes redirAttr) {/*from   w w  w  . j  a  v a 2 s  . c o  m*/

    redirAttr.addFlashAttribute(PathDef.METHOD_LOGGED_OUT, true);

    UriComponents uc = fromMethodCall(on(LoginController.class).init(locale, sitePref, request)).build();

    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView(uc.toUriString(), true));
    return mav;
}

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

@RequestMapping(params = "redirect")
public ModelAndView redirect(Authentication auth, Locale locale, SitePreference sitePref,
        HttpServletRequest request, HttpServletResponse response) {
    assertNotNull(auth);/*from   ww  w.  ja va  2  s . c om*/
    assertNotNull(locale);
    assertNotNull(sitePref);
    assertNotNull(request);
    assertNotNull(response);
    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView("/secure/text"));
    return mav;
}

From source file:com.fengduo.spark.commons.component.ComponentController.java

protected ModelAndView createFileJsonMav(ResultCode code, String msg, String object) {
    ModelAndView mav = new ModelAndView();
    mav.setView(new MappingJackson2JsonView());
    mav.addObject("error", code.value);
    mav.addObject("message", msg);
    mav.addObject("url", object == null ? StringUtils.EMPTY : object);
    return mav;//  w  w  w  .  jav  a 2 s. c o  m
}

From source file:com.fengduo.bee.commons.component.ComponentController.java

protected ModelAndView createJsonMav(String msg, ResultCode code, Object object) {
    ModelAndView mav = new ModelAndView();
    mav.setView(new MappingJackson2JsonView());
    mav.addObject("code", Integer.toString(code.value));
    mav.addObject("message", msg);
    mav.addObject("data", object == null ? StringUtils.EMPTY : object);
    return mav;/*from  w ww  . j  a v  a 2 s  .  c om*/
}

From source file:com.fengduo.bee.commons.component.ComponentController.java

protected ModelAndView createFileJsonMav(ResultCode code, String msg, String object) {
    ModelAndView mav = new ModelAndView();
    mav.setView(new MappingJackson2JsonView());
    mav.addObject("code", code.value);
    mav.addObject("message", msg);
    mav.addObject("file_path", object);// ?
    mav.addObject("url", object == null ? StringUtils.EMPTY : object);
    return mav;/* w w  w  .  j  a  v  a 2s.c  o  m*/
}

From source file:code.tianmao.h5.controller.BackendExceptionController.java

protected ModelAndView prepareExceptionInfo(HttpServletRequest request, HttpStatus httpStatus, String errorCode,
        String errorMessage) {/*from  w ww . ja v a2  s  .  c  o m*/
    Map<String, Object> models = new LinkedHashMap<>();
    models.put("errorCode", errorCode);
    models.put("errorMessage", errorMessage);
    ModelAndView modelAndView = new ModelAndView();
    if (noNeedWrapper(request)) {
        modelAndView.setView(DEFAULT_JSON_VIEW);
        modelAndView.addAllObjects(models);
        return modelAndView;
    } else {
        modelAndView.setViewName("error");
        modelAndView.addAllObjects(models);
        return modelAndView;
    }
}

From source file:com.venilnoronha.dzone.feed.web.ArticlesRSSController.java

@RequestMapping(value = "/rss/articles", method = RequestMethod.GET)
public ModelAndView articlesRssByLastModified(HttpEntity<byte[]> requestEntity, HttpServletRequest request,
        HttpServletResponse response) throws ParseException {
    HttpUtils.logUserIP("ArticlesRSS", request);
    String lastModified = requestEntity.getHeaders().getFirst("If-Modified-Since");
    if (lastModified == null) {
        lastModified = requestEntity.getHeaders().getFirst("If-None-Match");
    }//  w  w w. j ava2 s  . co  m
    PageRequest page = new PageRequest(0, feedSize, Direction.DESC, "articleDate");
    Page<Article> articlePage;
    if (lastModified != null) {
        Date lastModifiedDt = HTTP_FORMAT.parse(lastModified);
        articlePage = articlesRepository.findByArticleDateBetween(lastModifiedDt, new Date(), page);
    } else {
        articlePage = articlesRepository.findAll(page);
    }
    Iterator<Article> articlesIter = articlePage.iterator();
    List<Article> articles = new ArrayList<>();
    Date newLastModified = null;
    while (articlesIter.hasNext()) {
        Article article = articlesIter.next();
        Date articleDate = article.getArticleDate();
        if (newLastModified == null || newLastModified.before(articleDate)) {
            newLastModified = articleDate;
        }
        articles.add(article);
    }
    if (articles.isEmpty() && lastModified != null) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return null;
    } else {
        response.setHeader("ETag", HTTP_FORMAT.format(newLastModified));
        response.setHeader("Last-Modified", HTTP_FORMAT.format(newLastModified));
        ModelAndView mav = new ModelAndView();
        mav.setView(new ArticlesRSSView(articles));
        return mav;
    }
}

From source file:com.venilnoronha.dzone.feed.web.LinksRSSController.java

@RequestMapping(value = "/rss/links", method = RequestMethod.GET)
public ModelAndView linksRssByLastModified(HttpEntity<byte[]> requestEntity, HttpServletRequest request,
        HttpServletResponse response) throws ParseException {
    HttpUtils.logUserIP("LinksRSS", request);
    String lastModified = requestEntity.getHeaders().getFirst("If-Modified-Since");
    if (lastModified == null) {
        lastModified = requestEntity.getHeaders().getFirst("If-None-Match");
    }/*  www .j ava  2s.  c  o  m*/
    PageRequest page = new PageRequest(0, feedSize, Direction.DESC, "linkDate");
    Page<Link> linkPage;
    if (lastModified != null) {
        Date lastModifiedDt = HTTP_FORMAT.parse(lastModified);
        linkPage = linksRepository.findByLinkDateBetween(lastModifiedDt, new Date(), page);
    } else {
        linkPage = linksRepository.findAll(page);
    }
    Iterator<Link> linksIter = linkPage.iterator();
    List<Link> links = new ArrayList<>();
    Date newLastModified = null;
    while (linksIter.hasNext()) {
        Link link = linksIter.next();
        Date linkDate = link.getLinkDate();
        if (newLastModified == null || newLastModified.before(linkDate)) {
            newLastModified = linkDate;
        }
        links.add(link);
    }
    if (links.isEmpty() && lastModified != null) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return null;
    } else {
        response.setHeader("ETag", HTTP_FORMAT.format(newLastModified));
        response.setHeader("Last-Modified", HTTP_FORMAT.format(newLastModified));
        ModelAndView mav = new ModelAndView();
        mav.setView(new LinksRSSView(links));
        return mav;
    }
}

From source file:net.mindengine.oculus.frontend.web.controllers.test.TestCreateController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {
    User user = getUser(request);/*ww  w  . j a  v  a  2 s.com*/
    user.verifyPermission("test_managment");

    Test test = (Test) command;
    test.setAuthorId(user.getId());
    Long id = testDAO.create(test);
    test.setId(id);

    updateTestCustomizationValues(request, test);

    testParametersDAO.saveTestParameters(request, test);

    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView("../test/display?id=" + id));
    return mav;
}