Пример #1
0
  @RequestMapping(value = "/admin/speaker/{speakerId}", method = RequestMethod.POST)
  public String editSpeaker(
      @PathVariable("speakerId") Long speakerId,
      @RequestParam MultipartFile pictureFile,
      @Valid Speaker speakerForm,
      BindingResult result,
      HttpServletRequest request) {

    if (request.getParameter("cancel") != null) {
      return "redirect:/s/admin/index";
    }

    if (result.hasErrors()) {
      return "/admin/add-speaker";
    }

    final Speaker speakerFromDb = businessService.getSpeaker(speakerId);

    speakerFromDb.setBio(speakerForm.getBio());
    speakerFromDb.setTwitterId(speakerForm.getTwitterId());
    speakerFromDb.setGooglePlusId(speakerForm.getGooglePlusId());
    speakerFromDb.setFirstName(speakerForm.getFirstName());
    speakerFromDb.setLastName(speakerForm.getLastName());

    if (pictureFile != null && pictureFile.getSize() > 0) {

      final FileData pictureData;
      if (speakerFromDb.getPicture() == null) {
        pictureData = new FileData();
      } else {
        pictureData = speakerFromDb.getPicture();
      }

      try {

        pictureData.setFileData(IOUtils.toByteArray(pictureFile.getInputStream()));
        pictureData.setFileSize(pictureFile.getSize());
        pictureData.setFileModified(new Date());
        pictureData.setName(pictureFile.getOriginalFilename());
        pictureData.setType(pictureFile.getContentType());

      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      speakerFromDb.setPicture(pictureData);

      String message = "File '" + pictureData.getName() + "' uploaded successfully";
      // FlashMap.setSuccessMessage(message);
    }

    businessService.saveSpeaker(speakerFromDb);

    // FlashMap.setSuccessMessage("The speaker was edited successfully.");
    return "redirect:/s/admin/speakers";
  }
Пример #2
0
  @RequestMapping(value = "/admin/speaker", method = RequestMethod.POST)
  public String addSpeaker(
      @RequestParam MultipartFile pictureFile,
      @Valid Speaker speakerForm,
      BindingResult result,
      HttpServletRequest request) {

    if (request.getParameter("cancel") != null) {
      return "redirect:/s/admin/speakers";
    }

    if (result.hasErrors()) {
      return "/admin/add-speaker";
    }

    if (pictureFile != null && pictureFile.getSize() > 0) {

      final FileData pictureData = new FileData();

      try {

        pictureData.setFileData(IOUtils.toByteArray(pictureFile.getInputStream()));
        pictureData.setFileSize(pictureFile.getSize());
        pictureData.setFileModified(new Date());
        pictureData.setName(pictureFile.getOriginalFilename());
        pictureData.setType(pictureFile.getContentType());

      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      speakerForm.setPicture(pictureData);

      String message = "File '" + speakerForm.getPicture().getName() + "' uploaded successfully";
      // FlashMap.setSuccessMessage(message);

    }

    Speaker savedSpeaker = businessService.saveSpeaker(speakerForm);

    // FlashMap.setSuccessMessage("The speaker was added successfully.");
    return "redirect:/s/admin/speakers";
  }