Exemplo n.º 1
0
  @RequestMapping(value = "/vote/{id}.jspx")
  public String view(
      @PathVariable("id") Integer id,
      HttpServletRequest request,
      HttpServletResponse response,
      org.springframework.ui.Model modelMap) {
    Response resp = new Response(request, response, modelMap);
    List<String> messages = resp.getMessages();
    Vote vote = service.get(id);
    if (!Validations.exist(vote, messages, "Vote", id)) {
      return resp.notFound();
    }

    Site currSite = Context.getCurrentSite(request);
    modelMap.addAttribute("vote", vote);
    Map<String, Object> data = modelMap.asMap();
    ForeContext.setData(data, request);
    return currSite.getTemplate(VIEW_TEMPLATE);
  }
Exemplo n.º 2
0
  @RequestMapping(value = "/vote.jspx")
  public String form(
      Integer id,
      HttpServletRequest request,
      HttpServletResponse response,
      org.springframework.ui.Model modelMap) {
    Response resp = new Response(request, response, modelMap);
    List<String> messages = resp.getMessages();
    if (!Validations.notNull(id, messages, "id")) {
      return resp.badRequest();
    }
    Vote vote = service.get(id);
    if (!Validations.exist(vote, messages, "Vote", id)) {
      return resp.notFound();
    }

    modelMap.addAttribute("vote", vote);
    Site site = Context.getCurrentSite(request);
    Map<String, Object> data = modelMap.asMap();
    ForeContext.setData(data, request);
    return site.getTemplate(TEMPLATE);
  }
Exemplo n.º 3
0
  @RequestMapping(value = "/vote.jspx", method = RequestMethod.POST)
  public String submit(
      Integer id,
      Integer[] optionIds,
      HttpServletRequest request,
      HttpServletResponse response,
      org.springframework.ui.Model modelMap) {
    Response resp = new Response(request, response, modelMap);
    String cookie = Site.getIdentityCookie(request, response);
    String result = validateSubmit(request, resp, cookie, id, optionIds);
    if (resp.hasErrors()) {
      return result;
    }

    Integer userId = Context.getCurrentUserId(request);
    String ip = Servlets.getRemoteAddr(request);
    service.vote(id, optionIds, userId, ip, cookie);
    resp.addData("id", id);
    return resp.post();
  }