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:org.openmrs.module.patientflags.web.FindFlaggedPatientsEmailController.java

/**
 *  Handle the request to create an flag email
 *//*from w  w  w.  ja va 2 s .co m*/

@RequestMapping(method = RequestMethod.GET)
public ModelAndView processRequest(@ModelAttribute("flag") Flag flag, BindingResult result,
        SessionStatus status) {

    if (result.hasErrors()) {
        throw new APIException("Invalid parameter passed to FindFlaggedPatientsEmailController");
    }

    // get all Patients that trigger the selected Flag
    FlagService flagService = Context.getService(FlagService.class);
    flag = flagService.getFlag(flag.getFlagId());
    Cohort flaggedPatients = flagService.getFlaggedPatients(flag);
    Cohort allPatients = Context.getPatientSetService().getAllPatients();

    // create the model map
    ModelMap model = new ModelMap();
    model.addAttribute("flag", flag);
    model.addAttribute("allPatients", allPatients);
    if (flaggedPatients != null) {
        model.addAttribute("flaggedPatients", flaggedPatients.getMemberIds());
    } else {
        model.addAttribute("flaggedPatients", null);
    }

    // clears the command object from the session
    status.setComplete();

    // displays the query results
    return new ModelAndView("/module/patientflags/findFlaggedPatientsEmailResults", model);
}

From source file:org.esupportail.dining.web.controllers.EditAdminController.java

@RequestMapping
public ModelAndView renderEditAdminView(HttpServletRequest request) throws Exception {

    ModelMap model = new ModelMap();

    User user = this.authenticator.getUser();
    model.put("user", user);

    // try {/*from   w  ww .  ja  v a 2s.c o  m*/

    /* Get all area in the current feed */

    try {
        Set<String> areaList = new HashSet<String>();
        for (Restaurant r : this.feed.getFeed().getRestaurants()) {
            areaList.add(r.getArea());
        }
        model.put("areaList", areaList);
    } catch (Exception e) {
        // Here we go if the URL isn't set.
    }

    String[] areanames = null;
    List<FeedInformation> feedInfoList = new ArrayList<FeedInformation>();
    ResultSet results = null;
    try {
        results = this.dc.executeQuery("SELECT * FROM PATHFLUX");

        while (results.next()) {
            FeedInformation feedInfo = new FeedInformation(results.getInt("id"), results.getString("name"),
                    results.getString("areaname"), results.getString("urlflux"),
                    results.getBoolean("is_default"));
            feedInfoList.add(feedInfo);
        }

    } catch (SQLException e) {
        // URL isn't set yet...
    }

    try {
        for (FeedInformation fi : feedInfoList) {
            if (fi.isDefault()) {
                String areaname = fi.getAreaname();
                areanames = (areaname == null ? "" : areaname).split(",");
            }
        }
    } catch (Exception e) {
        // URL may be set be default area is not
    }
    model.put("feedList", feedInfoList);
    model.put("defaultArea", areanames);

    /* Action urlFeed set urlError if form URL was not well-formed */
    String hasError = request.getParameter("urlError");
    if (hasError != null) {
        model.put("urlError", hasError);
    }

    /* Action setDefaultArea set urlError if form URL was not well-formed */
    String areaSubmit = request.getParameter("areaSubmit");
    if (areaSubmit != null) {
        model.put("areaSubmit", areaSubmit);
    }

    /* From ForceFeedUpdate */
    if (request.getParameter("update") != null) {
        Boolean isUpdated = new Boolean(request.getParameter("update"));
        if (isUpdated.booleanValue()) {
            model.put("updateFeed", "The feed has been correctly updated");
        } else {
            model.put("updateFeed", "The feed is already up to date");
        }
    }
    return new ModelAndView("editadmin", model);
}

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

@RequestMapping(value = "/delete/{id}")
public ModelMap delete(@PathVariable Integer id) {
    ModelMap result = new ModelMap();
    cityService.deleteById(id);/*  ww w.ja  v  a2s.  c  o  m*/
    result.put("msg", "?!");
    return result;
}

From source file:org.ngrinder.user.controller.UserControllerTest.java

/**
 * Test method for//from w w  w.  ja  v  a2 s  .  c  o m
 * {@link org.ngrinder.user.controller.UserController#getOne(org.ngrinder.model.User,
 * org.springframework.ui.ModelMap)}
 * .
 */
@Test
public void testGetOne() {
    ModelMap model = new ModelMap();
    userController.getOne(getTestUser().getUserId(), model);
    User user = (User) model.get("user");
    assertThat(user.getId(), is(getTestUser().getId()));
}

From source file:org.openmrs.module.formfilter.web.controller.ViewFormFilterControllerTest.java

/**
 * @see {@link ViewFormFilterController#viewFormFilter(ModelMap, Integer, Integer)}
 *///from w  w w.  ja v a 2s  .  c om
@Test
@Verifies(value = "should return FormFilter by form filter id", method = "viewFormFilter(ModelMap, Integer, Integer)")
public void viewFormFilter_ShouldReturnFormFilterByFormFilterId() {
    ViewFormFilterController controller = new ViewFormFilterController();
    ModelMap model = new ModelMap();
    controller.viewFormFilter(model, null, "1");
    Assert.assertNotNull(((FormFilter) model.get("formfilter")));
}

From source file:game.kalaha.test.ModelControlTest.java

@Test
public void testPlayerTurn() {
    ModelMap model = new ModelMap();
    String functionReturn = controller.playerTurn(model);
    assertFalse("Wrong capitalization hasturn", model.containsKey("hasTurn"));
    assertTrue("No hasturn in the model", model.containsKey("hasturn"));
    assertEquals("Function return unexpected", "turn_status", functionReturn);
}

From source file:fragment.web.SystemHealthControllerTest.java

@Before
public void init() throws Exception {
    map = new ModelMap();
    calendar = Calendar.getInstance();
    defaultServiceInstance = serviceInstanceDao.find(1L);
    request = new MockHttpServletRequest();

}

From source file:com.mtt.myapp.user.controller.UserControllerTest.java

@Test
public void testUpdate() {
    // test update the role of current user.
    ModelMap model = new ModelMap();
}

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

@Secured("ROLE_ADMINISTRATOR")
@RequestMapping(value = { "/create/", "/create" }, method = RequestMethod.POST)
@SiteTitle("{navigation.revision.create}")
public ModelAndView createRevisionSubmit(@Valid @ModelAttribute("revisionForm") RevisionForm revisionForm,
        BindingResult result, Model model) {
    if (result.hasErrors()) {
        ModelMap mm = new ModelMap();
        mm.addAttribute("revisionForm", revisionForm);
        mm.addAttribute(model);//from w w w .  j  a  v a  2 s.  c o  m

        return new ModelAndView("revision_create", mm);
    } else {
        revisionService.createRevision(mapper.map(revisionForm, Revision.class));

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

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

@Secured("ROLE_ADMINISTRATOR")
@RequestMapping(value = { "/create", "/create/" }, method = RequestMethod.POST)
@SiteTitle("{navigation.userrole.create}")
public ModelAndView createUserRoleSubimt(@Valid @ModelAttribute("userRoleForm") UserRoleForm userRoleForm,
        BindingResult result, Model model) {
    if (result.hasErrors()) {
        ModelMap mm = new ModelMap();
        mm.addAttribute(model);/*from  w  w  w. j  a v a 2 s . c  o  m*/
        mm.addAttribute("userRoleForm", userRoleForm);

        return new ModelAndView("userrole_create", mm);
    } else {
        userRoleService.createUserRole(mapper.map(userRoleForm, UserRole.class));

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