コード例 #1
0
  @RequestMapping(value = "/{id}/control-letters/create", method = RequestMethod.GET)
  public String showControlLetterCreateForm(@PathVariable("id") int id, Model model) {
    ControlLetter controlLetter = new ControlLetter();
    // TODO: Validate income id that coming from form
    controlLetter.setIncomeId(id);

    List<Employee> employees = employeeService.findAll(Employee.EmployeePosition.CASIER.getId());

    model.addAttribute("controlLetter", controlLetter);
    model.addAttribute("employees", employees);

    return "controlLetter/edit";
  }
コード例 #2
0
  @RequestMapping(value = "/{invoiceId}/control-letters/{id}")
  public String showControlLetter(
      @PathVariable("invoiceId") int invoiceId, @PathVariable("id") int id, Model model) {

    ControlLetter controlLetter = controlLetterService.find(id);
    if (controlLetter == null) throw new ResourceNotFoundException();
    controlLetter.setIncomeId(invoiceId);

    List<Employee> employees = employeeService.findAll(Employee.EmployeePosition.CASIER.getId());

    model.addAttribute("employees", employees);
    model.addAttribute("controlLetter", controlLetter);
    return "controlLetter/edit";
  }
コード例 #3
0
  @RequestMapping(value = "/{id}/control-letters", method = RequestMethod.POST)
  public String createOrUpdateControlLetter(
      @PathVariable("id") int invoiceId,
      @ModelAttribute("controlLetter") @Validated ControlLetter controlLetter,
      BindingResult bindingResult,
      Model model,
      RedirectAttributes redirectAttributes) {

    if (!bindingResult.hasErrors()) controlLetterValidator.validate(controlLetter, bindingResult);

    if (bindingResult.hasErrors()) {
      List<Employee> employees = employeeService.findAll(Employee.EmployeePosition.CASIER.getId());
      model.addAttribute("employees", employees);

      return "controlLetter/edit";
    }

    return handleSaving(
        controlLetter,
        controlLetterService,
        redirectAttributes,
        "tickets-invoices/" + invoiceId + "/control-letters");
  }