コード例 #1
0
  @RequestMapping(method = RequestMethod.POST)
  protected String doPost(
      ModelMap model,
      String computerId,
      @Valid Computer computerEdit,
      BindingResult result,
      final RedirectAttributes redirectAttributes) {

    computerEdit.setId(Integer.valueOf(computerId));

    if (!result.hasErrors()) {

      computerService.update(computerEdit);

      Computer computerChanged = computerService.readFilterByID(Long.valueOf(computerId));

      List<ComputerDTO> computerDTOs = new ArrayList<ComputerDTO>();
      computerDTOs.add(MapComputer.computerToDTO(computerChanged));

      PageWrapper page = new PageWrapper();
      page.setPageNumber(1);
      page.setComputerPerPage(20);
      page.setOrderDirection("ASC");
      page.setOrderBy("c.id");
      page.setFilterName(computerEdit.getName());

      computerService.readByPage(page);

      page.setNumberOfPages(
          (Integer) (page.getTotalNumberOfRecords() / page.getComputerPerPage()) + 1);

      redirectAttributes.addFlashAttribute("pageData", page);
      return "redirect:Home";
    } else {

      model.addAttribute("computerEdit", computerEdit);
      model.addAttribute("companyId", computerEdit.getCompany().getId());
      model.addAttribute(
          "dateFormat",
          DateTimeFormat.patternForStyle("S-", LocaleContextHolder.getLocale()).toLowerCase());

      List<Company> companies = companyService.readAll();
      model.addAttribute("companies", companies);

      return "editComputer";
    }
  }
コード例 #2
0
  @RequestMapping(method = RequestMethod.GET)
  protected String doGet(ModelMap model, String idComputer) {

    List<Company> companies = companyService.readAll();
    model.addAttribute("companies", companies);

    Computer c = computerService.readFilterByID(Long.valueOf(idComputer));

    model.addAttribute("computerEdit", c);
    if (c.getCompany() != null) model.addAttribute("companyId", c.getCompany().getId());
    else model.addAttribute("companyId", 0);
    model.addAttribute(
        "dateFormat",
        DateTimeFormat.patternForStyle("S-", LocaleContextHolder.getLocale()).toLowerCase());

    return "editComputer";
  }