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:controller.PublisherController.java

@RequestMapping(method = RequestMethod.POST)
public ModelAndView onSubmit(HttpServletRequest request, @ModelAttribute("publisher") Publisher publisher) {
    //pass validation if they enter "TEST" and "TEST"
    String informationMessage = "";
    String errorMessage = "";
    String publisherToDelete = request.getParameter("delete");
    if (!(publisherToDelete == null || publisherToDelete.isEmpty())) {
        try {/*  w w  w . j  a  v a2s. c om*/
            PublisherBO.deletePublisher(Integer.parseInt(publisherToDelete));
            informationMessage = "Publisher deleted";
        } catch (Exception ex) {
            System.out.println("Error deleting publisher");
            errorMessage = "Error deleting publisher";
        }
    } else {

        System.out.println("About to add a publisher (" + publisher.getName() + ")");
        try {
            PublisherBO.insertPublisher(publisher);
            informationMessage = "Publisher added";
        } catch (Exception ex) {
            errorMessage = "Error adding publisher";
            System.out.println("Error inserting publisher");
        }
    }

    ModelAndView mv;
    mv = new ModelAndView("publisher");
    mv.addObject("publishers", PublisherBO.getPublishers());
    mv.addObject("errorMessage", errorMessage);
    mv.addObject("informationMessage", informationMessage);
    mv.addObject("menu", new Menu());

    return mv;
}

From source file:com.udemy.controller.CursoController.java

@GetMapping("/listcursos")
public ModelAndView listAllCursos() {
    ModelAndView mav = new ModelAndView(CURSOS_VIEW);
    LOG.info("Call: " + "listAllCursos()");
    mav.addObject("curso", new Curso());
    mav.addObject("cursos", cursoServicio.listaAllCursos());
    return mav;//from  ww w.  j  a  v  a2s.  com
}

From source file:br.com.arduinoweb.controller.ArduinoController.java

@RequestMapping("/Log")
public ModelAndView Log(HttpSession session) {
    ModelAndView mv = new ModelAndView("Admin/Log");
    mv.addObject("listLog", new LogService().getLogs());
    return mv;/* w w  w  . ja  va 2s . c  om*/
}

From source file:com.castlemock.web.mock.rest.web.mvc.controller.application.UpdateRestApplicationController.java

@PreAuthorize("hasAuthority('MODIFIER') or hasAuthority('ADMIN')")
@RequestMapping(value = "/{projectId}/application/{applicationId}/update", method = RequestMethod.GET)
public ModelAndView defaultPage(@PathVariable final String projectId,
        @PathVariable final String applicationId) {
    final ReadRestApplicationOutput output = serviceProcessor
            .process(new ReadRestApplicationInput(projectId, applicationId));
    final ModelAndView model = createPartialModelAndView(PAGE);
    model.addObject(REST_APPLICATION, output.getRestApplication());
    model.addObject(REST_PROJECT_ID, projectId);
    return model;
}

From source file:com.leapfrog.lfaeventmanager.admin.controller.EventController.java

@RequestMapping(value = "index", method = RequestMethod.GET)
public ModelAndView index(@ModelAttribute(value = "event") EventList eventList,
        @Context HttpServletRequest request) {
    ModelAndView mv = new ModelAndView("event/index");
    mv.addObject("eventList", eventService.getAll());
    return mv;/*from   w w  w . j  a v  a2  s. c  om*/
}

From source file:com.library.bookarticlelibrary.controller.ArticlesController.java

@RequestMapping(value = "/articles/article/editarticle/{articleId}", method = RequestMethod.GET)
public ModelAndView editArticle(@PathVariable("articleId") int articleId) {
    Article article = articleDao.get(articleId);
    ModelAndView model = new ModelAndView("editarticle");
    model.addObject("title", "Edit Article");
    model.addObject("article", article);

    return model;
}

From source file:com.library.bookarticlelibrary.controller.JournalsController.java

@RequestMapping(value = "/journals", method = RequestMethod.GET)
public ModelAndView displayJournals() {
    ModelAndView model = new ModelAndView("journals");
    List<Journal> journalList = journalDao.list();
    model.addObject("title", "journals");
    model.addObject("journalList", journalList);

    return model;
}

From source file:security.LoginController.java

@RequestMapping("/login")
public ModelAndView login(@Valid @ModelAttribute Credentials credentials, BindingResult bindingResult,
        @RequestParam(required = false) boolean showError) {
    Assert.notNull(credentials);/*  w  ww. ja v a2 s .co  m*/
    Assert.notNull(bindingResult);

    ModelAndView result;

    result = new ModelAndView("security/login");
    result.addObject("credentials", credentials);
    result.addObject("showError", showError);

    return result;
}

From source file:br.com.alura.casadocodigo.controllers.ProdutosController.java

@RequestMapping("/form")
public ModelAndView form(Produto produto) {
    ModelAndView modelAndView = new ModelAndView("produtos/form");
    modelAndView.addObject("tipos", TipoPreco.values());
    System.out.println("values " + Arrays.toString(TipoPreco.values()));
    return modelAndView;
}

From source file:br.com.joaops.smt.controller.SystemUserPermissionController.java

@RequestMapping(method = RequestMethod.GET)
public ModelAndView index(HttpServletRequest request, HttpServletResponse response, Pageable p) {
    ModelAndView mav = new ModelAndView("/system/permission/index");
    mav.addObject("page", systemUserPermissionService.searchAllUsersPermissions(p));
    return mav;/*  ww  w.j  a  v a 2  s .com*/
}