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(String attributeName, @Nullable Object attributeValue) 

Source Link

Document

Construct a new ModelMap containing the supplied attribute under the supplied name.

Usage

From source file:org.jasig.portlet.weather.portlet.WeatherEditController.java

@RequestMapping
public ModelAndView renderEditView(RenderRequest request, RenderResponse response) throws Exception {
    final PortletPreferences preferences = request.getPreferences();
    final List<SavedLocation> savedLocations = this.weatherService.getSavedLocations(preferences);

    ModelMap model = new ModelMap("savedLocations", savedLocations);
    return new ModelAndView("edit", model);
}

From source file:com.gvmax.web.api.AdminAPI.java

@RequestMapping(value = "/users", method = RequestMethod.GET)
@Timed/*from   w w  w  . j a  va  2  s  .  c o  m*/
@ExceptionMetered
public ModelMap users(@RequestParam(value = "pin", required = true) String pin,
        @RequestParam(defaultValue = "0", required = false) int offset,
        @RequestParam(defaultValue = "10", required = false) int limit, HttpSession session) {
    if (offset < 0) {
        offset = 0;
    }
    if (limit < 1) {
        limit = 10;
    }
    User user = getUser(service, session, pin);
    if (user != null && user.getEmail().equals(adminAccount)) {
        return new ModelMap("users", service.getUsers(offset, limit));
    }
    return null;
}

From source file:info.gehrels.voting.web.AdministrateBallotLayoutController.java

private ModelAndView createModelAndView(BallotLayoutBuilderBean form) {
    return new ModelAndView("administrateBallotLayout", new ModelMap("ballotLayoutBuilderBean", form));
}

From source file:org.openinfinity.tagcloud.web.controller.HomeController.java

@Log
@AuditTrail(argumentStrategy = ArgumentStrategy.ALL)
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody Map<String, ? extends Object> create(@RequestBody SearchModel searchModel) {
    List<Tag> required = new ArrayList<Tag>();
    List<Tag> preferred = new ArrayList<Tag>();
    List<Tag> nearby = new ArrayList<Tag>();

    for (TagModel tagModel : searchModel.getRequired()) {
        required.add(tagService.loadById(tagModel.getId()));
    }//from www  .  j  a  v a2  s  .  c o  m
    for (TagModel tagModel : searchModel.getPreferred()) {
        preferred.add(tagService.loadById(tagModel.getId()));
    }
    for (TagModel tagModel : searchModel.getNearby()) {
        nearby.add(tagService.loadById(tagModel.getId()));
    }

    double radius = Utils.calcDistanceGCS(searchModel.getBounds()[0], searchModel.getBounds()[1],
            searchModel.getBounds()[2], searchModel.getBounds()[3]) / 2;
    List<Result> results = targetService.loadByQuery(new TagQuery(required, preferred, nearby,
            searchModel.getLocation()[0], searchModel.getLocation()[1], radius));

    Collections.sort(results);
    return new ModelMap("results", results);
}

From source file:org.openinfinity.web.controller.ProductController.java

@Log
@AuditTrail(argumentStrategy = ArgumentStrategy.ALL)
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody Map<String, ? extends Object> create(@Valid @RequestBody ProductModel productModel,
        HttpServletResponse response) {/*ww w. j  a va  2 s . co  m*/
    Set<ConstraintViolation<ProductModel>> failures = validator.validate(productModel);
    if (failures.isEmpty()) {
        Product product = productService.create(productModel.getProduct());
        return new ModelMap("id", product.getId());
    } else {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return getValidationMessages(failures);
    }
}

From source file:com.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
@Timed/*  ww w . j  a  v  a 2  s.c  om*/
@ExceptionMetered
public ModelMap login(@RequestParam("email") String email, @RequestParam("password") String password,
        HttpSession session, HttpServletResponse resp) {
    try {
        User user = service.login(email, password);
        session.setAttribute("email", user.getEmail());
        return new ModelMap("result", "ok");
    } catch (DataAccessException e) {
        internalError(e, resp);
    } catch (IOException e) {
        invalidCredentials(resp);
    }
    return null;
}

From source file:com.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/logout", method = RequestMethod.GET)
@Timed//  ww w. java  2 s.  c  o m
@ExceptionMetered
public ModelMap logout(HttpSession session) {
    session.removeAttribute("email");
    return new ModelMap("result", "ok");
}

From source file:org.esupportail.portlet.filemanager.portlet.PortletController.java

@RequestMapping(value = { "VIEW" }, params = { "action=browseMobile" })
public ModelAndView browseMobile(RenderRequest request, RenderResponse response, @RequestParam String dir) {
    this.init(request);

    String decodedDir = pathEncodingUtils.decodeDir(dir);

    ModelMap model;/*w  w  w  .  j  a  v a  2  s. c om*/
    if (!(dir == null || dir.length() == 0 || decodedDir.equals(JsTreeFile.ROOT_DRIVE))) {
        if (this.serverAccess.formAuthenticationRequired(decodedDir, userParameters)) {
            ListOrderedMap parentPathes = pathEncodingUtils.getParentsEncPathes(decodedDir, null, null);
            // we want to get the (last-1) key of sortedmap "parentPathes"
            String parentDir = (String) parentPathes.get(parentPathes.size() - 2);
            model = new ModelMap("currentDir", dir);
            model.put("parentDir", parentDir);
            model.put("username", this.serverAccess.getUserPassword(decodedDir, userParameters).getUsername());
            model.put("password", this.serverAccess.getUserPassword(decodedDir, userParameters).getPassword());
            return new ModelAndView("authenticationForm-portlet-mobile", model);
        }
    }
    model = browse(dir);
    return new ModelAndView("view-portlet-mobile", model);
}

From source file:com.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/signup", method = RequestMethod.POST)
@Timed/*from w w w .  j av  a2  s. c om*/
@ExceptionMetered
public ModelMap signup(@RequestParam(value = "email") String email,
        @RequestParam(value = "password") String password,
        @RequestParam(value = "gvPassword", required = false) boolean isGVPassword, HttpSession session,
        HttpServletResponse resp) throws IOException {
    try {
        email = EmailUtils.normalizeEmail(email);
        RegistrationInfo info = service.signup(email, password, isGVPassword);
        if (info.isInvalidCredentials()) {
            invalidCredentials(resp);
            return null;
        }
        if (info.isRegistered()) {
            String message = "You are receiving this email because your account has been registered with GVMax\n"
                    + "GVMax is a service used to monitor GoogleVoice and provide notifications for incoming SMS and Voicemail\n"
                    + "GVMax also provides other services such as sending Group SMS's and integration with GoogleTalk, Twitter etc...\n"
                    + "You can view your account at https://www.gvmax.com\n" + "username: " + email + "\n";
            try {
                relay.sendEmail(relay.getEmailSender(), relay.getEmailSender(), email, "Welcome to GVMax",
                        message);
            } catch (Exception e) {
                logger.warn("Unable to send email: " + e.getMessage());
            }
        }
        session.setAttribute("email", email);
        return new ModelMap("info", info);
    } catch (DataAccessException e) {
        internalError(e, resp);
    }
    return null;
}

From source file:org.esupportail.portlet.filemanager.portlet.PortletController.java

@RequestMapping(value = { "VIEW" }, params = { "action=browseWai" })
public ModelAndView browseWai(RenderRequest request, RenderResponse response,
        @RequestParam(required = false) String dir, @RequestParam(required = false) String msg) {
    this.init(request);

    String decodedDir = pathEncodingUtils.decodeDir(dir);

    if (!serverAccess.isInitialized(userParameters)) {
        serverAccess.initializeServices(userParameters);
    }//from   ww  w  .  j a  v  a2 s .c o  m

    ModelMap model;
    if (!(dir == null || dir.length() == 0 || decodedDir.equals(JsTreeFile.ROOT_DRIVE))) {
        if (this.serverAccess.formAuthenticationRequired(decodedDir, userParameters)) {
            ListOrderedMap parentPathes = pathEncodingUtils.getParentsEncPathes(decodedDir, null, null);
            // we want to get the (last-1) key of sortedmap "parentPathes"
            String parentDir = (String) parentPathes.get(parentPathes.size() - 2);
            model = new ModelMap("currentDir", dir);
            model.put("parentDir", parentDir);
            model.put("username", this.serverAccess.getUserPassword(decodedDir, userParameters).getUsername());
            model.put("password", this.serverAccess.getUserPassword(decodedDir, userParameters).getPassword());
            if (msg != null)
                model.put("msg", msg);
            return new ModelAndView("authenticationForm-portlet-wai", model);
        }
    }

    model = browse(dir);
    FormCommand command = new FormCommand();
    model.put("command", command);
    if (msg != null)
        model.put("msg", msg);
    return new ModelAndView("view-portlet-wai", model);
}