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.pkrete.locationservice.admin.controller.mvc.AddUserController.java

@RequestMapping(method = RequestMethod.POST)
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute("userInfo") UserInfo userInfo, BindingResult result) throws Exception {
    validator.validate(userInfo, result);

    if (result.hasErrors()) {
        ModelMap model = new ModelMap();
        this.setReferenceData(request, model);
        return new ModelAndView("add_user", model);
    }/*  w ww.  ja  v a  2  s  . c  o  m*/

    userInfo.getUser().setCreator(getUser(request).getUsername());
    // Creating UserInfo creates both UserInfo and User
    if (!usersService.create(userInfo)) {
        throw new Exception("Creating user failed.");
    }
    return new ModelAndView("redirect:userowner.htm");
}

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

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

    when(mockRsService.findBySlug(eq(slug))).thenReturn(rollingStock());
    when(mockUserContext.getCurrentUser()).thenReturn(new AccountDetails(author()));

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

    assertEquals("review/new", viewName);

    assertTrue("Rolling stock not found", model.containsAttribute("rs"));
    assertEquals(rollingStock(), (RollingStock) model.get("rs"));

    assertTrue("Review form not found", model.containsAttribute("reviewForm"));
    ReviewForm reviewForm = (ReviewForm) model.get("reviewForm");

    assertEquals(rollingStock().getSlug(), reviewForm.getRsSlug());
    assertEquals(rollingStock().getLabel(), reviewForm.getRsLabel());
    assertEquals(author().getSlug(), reviewForm.getReview().getAuthor());
}

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

@RequestMapping(value = { "/clone/{id}", "/clone/{id}/" }, method = RequestMethod.GET)
@SiteTitle("{entity.configuration.clone}")
public ModelAndView cloneConfiguration(@PathVariable Long id) {
    ModelMap mm = new ModelMap();
    mm.addAttribute("configurationForm",
            mapper.map(configurationService.getConfigurationByID(id), ConfigurationForm.class));

    return new ModelAndView("configuration_clone", mm);
}

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

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

    Owner owner = getOwner(request);
    subjectMatter.setOwner(owner);//  w  w  w. ja v  a 2 s .  c om

    validator.validate(subjectMatter, result);

    if (result.hasErrors()) {
        ModelMap model = new ModelMap();
        model.put("languages", owner.getLanguages());
        return new ModelAndView("add_subjectmatter", model);
    }

    subjectMatter.setCreator(getUser(request).getUsername());
    if (!subjectMattersService.create(subjectMatter)) {
        throw new Exception("Creating subject matter failed.");
    }
    return new ModelAndView("redirect:subjectmatters.htm");
}

From source file:org.slc.sli.dashboard.unit.controller.ErrorControllerTest.java

@Test
public void testHandleTest() throws Exception {

    ModelMap model = new ModelMap();

    try {//from ww w . jav a  2s. c  om
        ModelAndView modelAndView = errorController.handleTest(model);
        assertTrue("ErrorController handleTest() should generate an exception!", false);
    } catch (Exception exception) {
        int dummy = 0;
    }

}

From source file:org.impalaframework.extension.mvc.util.RequestModelHelperTest.java

public void testImplicitParams() throws Exception {
    HttpServletRequest request = createMock(HttpServletRequest.class);
    expect(request.getParameterNames()).andReturn(new Enumeration<String>() {

        private String[] list = { "one", "two" };
        int index;

        public boolean hasMoreElements() {
            return (index < list.length);
        }/*  w w  w .  jav a 2  s  .co  m*/

        public String nextElement() {
            final String string = list[index];
            index++;
            return string;
        }

    });

    expect(request.getParameter("one")).andReturn("v1");
    expect(request.getParameter("two")).andReturn("v2");

    replay(request);
    final ModelMap modelMap = new ModelMap();
    RequestModelHelper.setParameters(request, modelMap);
    assertEquals(2, modelMap.size());
    verify(request);
}

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

@RequestMapping(value = { "/edit/{id}", "/edit/{id}/" }, method = RequestMethod.GET)
public ModelAndView editUserRole(@PathVariable Long id) {
    ModelMap mm = new ModelMap();
    mm.addAttribute("userRoleForm", mapper.map(userRoleService.getUserRoleByID(id), UserRoleForm.class));

    return new ModelAndView("userrole_edit", mm);
}

From source file:com.asual.summer.sample.web.TechnologyController.java

@RequestMapping("/add")
public ModelAndView add() {
    ModelMap model = new ModelMap();
    model.addAllAttributes(Arrays.asList(new Technology(), License.list(), Status.list()));
    return new ModelAndView("/add", model);
}

From source file:org.slc.sli.dashboard.web.controller.ConfigController.java

/**
 * Generic layout handler/*from www  . java2s.  c  o  m*/
 *
 * @deprecated retiring method
 * @param id
 * @param request
 * @return
 * @throws IllegalAccessException
 */
@Deprecated
@RequestMapping(value = CONFIG_URL, method = RequestMethod.GET)
public ModelAndView getConfig(HttpServletRequest request) throws IllegalAccessException {
    ModelMap model = new ModelMap();

    String token = SecurityUtil.getToken();
    GenericEntity staffEntity = userEdOrgManager.getStaffInfo(token);

    Boolean isAdmin = SecurityUtil.isAdmin();
    if (isAdmin != null && isAdmin.booleanValue()) {
        GenericEntity edOrg = (GenericEntity) staffEntity.get(Constants.ATTR_ED_ORG);
        boolean configUser = false;

        if (edOrg != null) {
            List<String> organizationCategories = (List<String>) edOrg.get(Constants.ATTR_ORG_CATEGORIES);
            if (organizationCategories != null && !organizationCategories.isEmpty()) {
                for (String educationAgency : organizationCategories) {
                    if (educationAgency != null && educationAgency.equals(Constants.LOCAL_EDUCATION_AGENCY)) {
                        configUser = true;
                        break;
                    } else if (educationAgency != null
                            && educationAgency.equals(Constants.STATE_EDUCATION_AGENCY)) {
                        configUser = true;
                        break;
                    }
                }
            }
        }
        if (configUser) {
            ConfigMap configMap = configManager.getCustomConfig(token, userEdOrgManager.getUserEdOrg(token));

            if (configMap != null) {
                model.addAttribute("configJSON", new GsonBuilder().create().toJson(configMap));
            } else {
                model.addAttribute("configJSON", "");
            }
        } else {
            model.addAttribute("configJSON", "nonLocalEducationAgency");

        }

        addCommonData(model, request);
        model.addAttribute(Constants.PAGE_TO_INCLUDE, DASHBOARD_CONFIG_FTL);
        return new ModelAndView(Constants.OVERALL_CONTAINER_PAGE, model);
    }
    throw new IllegalAccessException("Access Denied");
}

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

@RequestMapping(value = { "/edit/{id}", "/edit/{id}/" }, method = RequestMethod.GET)
@SiteTitle("{entity.revision.edit}")
public ModelAndView editRevision(@PathVariable Long id) {
    ModelMap mm = new ModelMap();
    mm.addAttribute("revisionForm", mapper.map(revisionService.getRevisionByID(id), RevisionForm.class));

    return new ModelAndView("revision_edit", mm);
}