Example usage for org.springframework.ui ModelMap ModelMap

List of usage examples for org.springframework.ui ModelMap ModelMap

Introduction

In this page you can find the example usage for org.springframework.ui ModelMap ModelMap.

Prototype

public ModelMap() 

Source Link

Document

Construct a new, empty ModelMap .

Usage

From source file:com.trenako.web.controllers.ReviewsControllerTests.java

@Test
public void shouldShowRollingStockReviews() {
    String slug = "acme-123456";
    ModelMap model = new ModelMap();
    RollingStockReviews value = new RollingStockReviews();

    when(mockRsService.findBySlug(eq(slug))).thenReturn(rollingStock());
    when(mockService.findByRollingStock(rollingStock())).thenReturn(value);

    String viewName = controller.reviews(slug, model);

    assertEquals("review/list", viewName);

    RollingStock rs = (RollingStock) model.get("rollingStock");
    assertNotNull("Rolling stock not found", rs);
    RollingStockReviews reviews = (RollingStockReviews) model.get("reviews");
    assertNotNull("Review not found", reviews);
}

From source file:org.esupportail.helpdeskviewer.web.WebControllerEdit.java

@RequestMapping("EDIT")
public ModelAndView renderEditView(RenderRequest request, RenderResponse response) throws Exception {

    ModelMap model = new ModelMap();
    final PortletPreferences prefs = request.getPreferences();
    String[] recupPrefDisplay_userTabs = prefs.getValues(WebController.PREF_TAB_USER, null);
    String[] recupPrefDisplay_managerTabs = prefs.getValues(WebController.PREF_TAB_MANAGER, null);
    String messageFile = prefs.getValue(WebController.PREF_MESSAGE_FILE, "_fr");
    String nbMaxTickets = prefs.getValue(WebController.PREF_MAX_TICKETS, "15");
    String nbMaxComments = prefs.getValue(WebController.PREF_MAX_COMMENTS, "1");

    ArrayOfString managerFilters = domainService
            .getInvolvementFilters((prefs.getValue(WebController.PREF_WSDL_LOCATION, null)), false);
    ArrayOfString userFilters = domainService
            .getInvolvementFilters((prefs.getValue(WebController.PREF_WSDL_LOCATION, null)), true);

    ArrayList<String> userTabPrefs = new ArrayList<String>();
    ArrayList<String> managerTabPrefs = new ArrayList<String>();
    int i = 0;// www .  j av  a  2s.  com
    for (String userFilter : userFilters.getString()) {
        if (Arrays.asList(recupPrefDisplay_userTabs).contains(userFilter.toLowerCase())) {
            i++;
            userTabPrefs.add(String.valueOf(i).concat(".").concat(userFilter).toLowerCase());
        } else {
            userTabPrefs.add(userFilter.toLowerCase());
        }
    }
    Collections.sort(userTabPrefs);
    i = 0;
    for (String managerFilter : managerFilters.getString()) {
        if (Arrays.asList(recupPrefDisplay_managerTabs).contains(managerFilter.toLowerCase())) {
            i++;
            managerTabPrefs.add(String.valueOf(i).concat(".").concat(managerFilter).toLowerCase());
        } else {
            managerTabPrefs.add(managerFilter.toLowerCase());
        }
    }
    Collections.sort(managerTabPrefs);
    boolean userViewMode = true;
    boolean managerViewMode = false;
    boolean maxTicketsViewMode = false;
    boolean maxCommentsViewMode = false;
    String isManagerViewAble = "false";

    if (prefs.isReadOnly(WebController.PREF_TAB_USER)) {
        userViewMode = false;
    }
    PortletSession session = request.getPortletSession();
    if (session != null) {
        isManagerViewAble = session.getAttribute("isManagerViewAble").toString();
    }
    if ((isManagerViewAble.equalsIgnoreCase("true")) && (!prefs.isReadOnly(WebController.PREF_TAB_MANAGER))) {
        managerViewMode = true;
    }
    if (!prefs.isReadOnly(WebController.PREF_MAX_TICKETS)) {
        maxTicketsViewMode = true;
    }
    if (!prefs.isReadOnly(WebController.PREF_MAX_COMMENTS)) {
        maxCommentsViewMode = true;
    }
    model.put("nbMaxTickets", nbMaxTickets);
    model.put("messageFile", messageFile);
    model.put("managerTabPrefs", managerTabPrefs);
    model.put("userTabPrefs", userTabPrefs);
    model.put("userViewMode", userViewMode);
    model.put("managerViewMode", managerViewMode);
    model.put("maxTicketsViewMode", maxTicketsViewMode);
    model.put("isManagerViewAble", isManagerViewAble);
    model.put("nbMaxComments", nbMaxComments);
    model.put("maxCommentsViewMode", maxCommentsViewMode);
    return new ModelAndView("edit-portlet", model);
}

From source file:com.pkrete.locationservice.admin.controller.mvc.AddOwnerController.java

@RequestMapping(method = RequestMethod.POST)
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute("owner") Owner owner, BindingResult result) throws Exception {

    validator.validate(owner, result);// ww w .j  av  a 2 s .c  om

    if (result.hasErrors()) {
        ModelMap model = new ModelMap();
        this.setReferenceData(request, model);
        return new ModelAndView("add_owner", model);
    }

    owner.setCreator(getUser(request).getUsername());
    if (!ownersService.create(owner)) {
        throw new Exception("Creating owner failed.");
    }
    return new ModelAndView("redirect:userowner.htm");
}

From source file:com.forexnepal.controller.HomeController.java

@RequestMapping(value = "/exchange_rates/all_time", method = RequestMethod.GET)
public @ResponseBody ModelMap allForexTime() {
    ModelMap map = new ModelMap();

    map.addAttribute("forexTimes", exchangeRatesService.getAllTime());
    return map;//from w w w.java  2s  . com
}

From source file:ask.springboot.controller.UserInfoController.java

@RequestMapping(value = "/delete/{id}")
public ModelMap delete(@PathVariable Integer id) {
    ModelMap result = new ModelMap();
    userInfoService.deleteById(id);/*  www  .j  ava  2  s  .  c  o m*/
    result.put("msg", "?!");
    return result;
}

From source file:cz.muni.fi.mir.controllers.SourceDocumentController.java

@Secured("ROLE_USER")
@RequestMapping(value = { "/create", "/create/" }, method = RequestMethod.POST)
@SiteTitle("{navigation.sourcedocument.create}")
public ModelAndView createSubmit(
        @Valid @ModelAttribute("sourceDocumentForm") SourceDocumentForm sourceDocumentForm,
        BindingResult result, Model model) {
    if (result.hasErrors()) {
        ModelMap mm = new ModelMap();
        mm.addAttribute("soureDocumentForm", sourceDocumentForm);
        mm.addAttribute(model);//from  w  w w  . j  a v  a2s.  c  o  m

        return new ModelAndView("sourcedocument_create", mm);
    } else {
        sourceDocumentService.createSourceDocument(mapper.map(sourceDocumentForm, SourceDocument.class));
        return new ModelAndView("redirect:/sourcedocument/list/");
    }
}

From source file:br.com.edo.atmlist.controller.ATMControllerTest.java

/**
 * Test of getATMListFromServer method, of class ATMController.
 *//*from   www.j  a  va 2  s  .c om*/
@Test
public void testGetATMListFromServer() {
    System.out.println("getATMListFromServer");
    ModelMap model = new ModelMap();
    ATMController instance = new ATMController();
    Object result = instance.getATMListFromServer(model);
    assertNotNull(result);
}

From source file:cz.muni.fi.mir.controllers.AnnotationValueController.java

@RequestMapping(value = { "/edit", "/edit/" }, method = RequestMethod.POST)
public ModelAndView editSubmit(
        @Valid @ModelAttribute("annotationValueForm") AnnotationValueForm annotationValueForm,
        BindingResult result, Model model) {
    if (result.hasErrors()) {
        ModelMap mm = new ModelMap();
        mm.addAttribute("annotationValueForm", annotationValueForm);
        mm.addAttribute(model);/* w ww .j a v  a 2  s  .  co  m*/
    } else {
        annotationValueSerivce.updateAnnotationValue(mapper.map(annotationValueForm, AnnotationValue.class));
    }
    return new ModelAndView("redirect:/annotationvalue/");
}

From source file:com.pkrete.locationservice.admin.controller.mvc.AddLibraryController.java

@RequestMapping(method = RequestMethod.POST)
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute("library") Library library, BindingResult result) throws Exception {

    library.setAreas(parseAreas(request, library));
    validator.validate(library, result);

    if (result.hasErrors()) {
        ModelMap model = new ModelMap();
        super.setReferenceData(request, model);
        return new ModelAndView("add_library", model);
    }/*from   w w w . j  av  a  2s  .  c  o  m*/

    library.setCreator(getUser(request).getUsername());
    if (!locationsService.create(library)) {
        throw new Exception("Creating library failed.");
    }

    return new ModelAndView("redirect:locations.htm");
}

From source file:cz.muni.fi.mir.controllers.ConfigurationController.java

@Secured("ROLE_ADMINISTRATOR")
@RequestMapping(value = { "/create", "/create/" }, method = RequestMethod.POST)
@SiteTitle("{entity.configuration.create}")
public ModelAndView createConfigurationSubmit(
        @Valid @ModelAttribute("configurationForm") ConfigurationForm configurationForm, BindingResult result,
        Model model) {/*w w  w.j a  v  a 2s. com*/
    if (result.hasErrors()) {
        ModelMap mm = new ModelMap();
        mm.addAttribute("configurationForm", configurationForm);
        mm.addAttribute(model);

        return new ModelAndView("configuration_create", mm);
    } else {
        configurationService.createConfiguration(mapper.map(configurationForm, Configuration.class));

        return new ModelAndView("redirect:/configuration/list/");
    }
}