예제 #1
0
  /** Saves the edited post from the Edit page and returns a result page. */
  @RequestMapping(value = "/edit", method = RequestMethod.POST)
  public String getEditPage(
      @ModelAttribute("postAttribute") PublicPost post,
      @RequestParam(value = "id", required = true) Long id,
      Model model) {
    logger.debug("Received request to view edit page");

    // Re-assign id
    post.setId(id);
    // Assign new date
    post.setDate(new Date());

    // Delegate to service
    if (publicService.edit(post) == true) {
      // Add result to model
      model.addAttribute("result", "Entry has been edited successfully!");
    } else {
      // Add result to model
      model.addAttribute("result", "You're not allowed to perform that action!");
    }

    // Add source to model to help us determine the source of the JSP page
    model.addAttribute("source", "Public");

    // Add our current role and username
    model.addAttribute(
        "role", SecurityContextHolder.getContext().getAuthentication().getAuthorities());
    model.addAttribute(
        "username", SecurityContextHolder.getContext().getAuthentication().getName());

    // This will resolve to /WEB-INF/jsp/crud-public/resultpage.jsp
    return "crud-public/resultpage";
  }
예제 #2
0
  /** Saves a new post from the Add page and returns a result page. */
  @RequestMapping(value = "/add", method = RequestMethod.POST)
  public String getAddPage(@ModelAttribute("postAttribute") PublicPost post, Model model) {
    logger.debug("Received request to view add page");

    // Add date today
    post.setDate(new Date());

    // Delegate to service
    if (publicService.add(post)) {
      // Success. Add result to model
      model.addAttribute("result", "Entry has been added successfully!");
    } else {
      // Failure. Add result to model
      model.addAttribute("result", "You're not allowed to perform that action!");
    }

    // Add source to model to help us determine the source of the JSP page
    model.addAttribute("source", "Public");

    // Add our current role and username
    model.addAttribute(
        "role", SecurityContextHolder.getContext().getAuthentication().getAuthorities());
    model.addAttribute(
        "username", SecurityContextHolder.getContext().getAuthentication().getName());

    // This will resolve to /WEB-INF/jsp/crud-public/resultpage.jsp
    return "crud-public/resultpage";
  }
예제 #3
0
  /** Retrieves the Edit page */
  @RequestMapping(value = "/edit", method = RequestMethod.GET)
  public String getEdit(@RequestParam(value = "id", required = true) Long id, Model model) {
    logger.debug("Received request to show edit page");

    // Retrieve existing post and add to model
    // This is the formBackingOBject
    model.addAttribute("postAttribute", publicService.getSingle(id));

    // Add source to model to help us determine the source of the JSP page
    model.addAttribute("source", "Public");

    // This will resolve to /WEB-INF/jsp/crud-public/editpage.jsp
    return "crud-public/editpage";
  }