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

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

Introduction

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

Prototype

public ModelAndView addObject(String attributeName, @Nullable Object attributeValue) 

Source Link

Document

Add an attribute to the model.

Usage

From source file:com.neeti.neg.controller.GlobalExceptionController.java

@ExceptionHandler(Exception.class)
public ModelAndView handleAllException(Exception ex) {

    ModelAndView model = new ModelAndView("errorpage");
    model.addObject("errMsg", ex.getMessage());
    ex.printStackTrace();//from   www  .  ja v a2  s.  co  m
    return model;

}

From source file:com.ravens.filters.GlobalDefaultExceptionHandler.java

@ExceptionHandler(value = Exception.class)
public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
    // If the exception is annotated with @ResponseStatus rethrow it and let
    // the framework handle it - like the OrderNotFoundException example
    // at the start of this post.
    // AnnotationUtils is a Spring Framework utility class.
    if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null)
        throw e;/*from w ww  .  j  ava  2 s  .  c o m*/

    // Otherwise setup and send the user to a default error-view.
    ModelAndView mav = new ModelAndView();
    mav.addObject("exception", e);
    mav.addObject("url", req.getRequestURL());
    mav.setViewName(DEFAULT_ERROR_VIEW);

    e.printStackTrace();
    return mav;
}

From source file:com.googlecode.jeeunit.example.spring.web.controller.LibraryController.java

@RequestMapping("/books.html")
public ModelAndView showBooks() {
    libraryService.fillLibrary();/*www .jav  a2  s.  c o m*/

    List<Book> books = libraryService.findBooks();
    ModelAndView mav = new ModelAndView("books");
    mav.addObject("books", books);
    return mav;
}

From source file:com.kdgregory.pathfinder.test.spring3.pkg2.ControllerB.java

@RequestMapping(value = "/bar.html", method = RequestMethod.GET)
protected ModelAndView getBar(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView mav = new ModelAndView("simple");
    mav.addObject("reqUrl", request.getRequestURI());
    mav.addObject("controller", getClass().getName());
    return mav;// w w  w  . ja v  a  2s  . c  o m
}

From source file:com.kdgregory.pathfinder.test.spring3.pkg2.ControllerB.java

@RequestMapping(value = "/baz.html", method = RequestMethod.POST)
protected ModelAndView setBaz(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView mav = new ModelAndView("simple");
    mav.addObject("reqUrl", request.getRequestURI());
    mav.addObject("controller", getClass().getName());
    return mav;// www  .java2s .  co m
}

From source file:nl.mok.mastersofcode.spectatorclient.controllers.CompetitionController.java

@RequestMapping(method = RequestMethod.GET, value = "/{id}")
public ModelAndView showCompetition(final HttpServletRequest request, @PathVariable int id) {

    ModelAndView mav = new ModelAndView();

    mav.addObject("page", new Object() {
        public String uri = "/spec/competition/" + id;
        public String redirect = request.getRequestURL().toString();
    });/*from w  ww. ja  v  a  2 s.  c om*/

    mav.addObject("competition", DataController.getCompetitionById(id).orElse(null));
    mav.addObject("currentCompetition", DataController.getCurrentCompetition());
    mav.addObject("currentRound", DataController.getCurrentRound());

    mav.setViewName("competition.twig");

    return mav;
}

From source file:web.mvc.controllers.HelloController.java

@RequestMapping("/hello")
public ModelAndView showHelloPage(@RequestParam(value = "user", required = false) String name) {
    ModelAndView mav = new ModelAndView("hello-page");
    mav.addObject("message", name == null ? "Hello guest!" : "Hello " + name + '!');
    return mav;//from   www  .ja  v a2 s . com
}

From source file:web.mvc.controllers.HelloController.java

@RequestMapping("/goodbye")
public ModelAndView showGoodbyePage(String name) {
    ModelAndView mav = new ModelAndView("hello-page");
    mav.addObject("message", "Goodbye user! " + name + '!');
    return mav;/*  w w  w.j  a  v  a2  s.c om*/
}

From source file:web.mvc.controllers.HelloController.java

@RequestMapping("/page/{user}")
public ModelAndView showMessagePage(@PathVariable("user") String name) {
    ModelAndView mav = new ModelAndView("hello-page");
    mav.addObject("message", name == null ? "Hello guest!" : "Hello " + name + '!');
    return mav;//from  w w  w .ja  v a 2  s . c om
}

From source file:gov.nih.nci.cabig.caaers.web.ae.ReconciliationReportController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String strReportId = request.getParameter("rrId");
    ReconciliationReport report = null;/*from   w w  w .j a  v a  2  s.com*/

    if (StringUtils.isNotEmpty(strReportId)) {
        report = reconciliationReportDao.getById(Integer.parseInt(strReportId));
    } else {
        report = (ReconciliationReport) request.getAttribute("report");
    }
    ModelAndView mv = new ModelAndView();
    mv.addObject("report", report);
    mv.setViewName("ae/ae_reconcile_report");
    return mv;
}