예제 #1
0
 @Action(
     value = "customer-edit-ajax",
     results = {
       @Result(
           name = "success",
           location = "/WEB-INF/content/ajax/customer/customer-edit-ajax.jsp")
     })
 public String customer_edit_ajax() {
   customer = customerService.get(customer.getId());
   session.put("customer", customer);
   session.put("imageList", customer.getImageOfList());
   session.put("defectList", customer.getDefectList());
   session.put("costList", customer.getCostList());
   this.carmarkList =
       carMarkService.getMarkForFactory(customer.getCarFactory().getId().toString());
   return SUCCESS;
 }
예제 #2
0
  @Action(
      value = "delete-pm-images",
      results = {
        @Result(
            name = "success",
            location = "/WEB-INF/content/ajax/customer/ajax-image-list-response.jsp"),
        @Result(
            name = "input",
            location = "/WEB-INF/content/ajax/customer/ajax-image-input-error-response.jsp"),
        @Result(name = "error", location = "/WEB-INF/content/ajax/customer/ajax-error-response.jsp")
      })
  public String deleteImagesAction() {
    try {
      if (customer.getId() == null || customer.getId() == 0l) {
        addFieldError("id", Messages.getString("emptyError"));
        return INPUT;
      }

      String[] imageIds = request.getParameterValues("imageIds[]");
      if (imageIds == null || imageIds.length <= 0) {
        addFieldError("imageIds", Messages.getString("emptyError"));
        return INPUT;
      }

      Customer cust = new Customer();
      cust = customerService.get(customer.getId());
      if (cust == null) {
        addFieldError("id", Messages.getString("wrongIdError"));
        return INPUT;
      }
      String filePathd = request.getSession().getServletContext().getRealPath("/") + "\\uploads";
      String filePath = "c:/temp/";
      for (int j = 0; j < imageIds.length; j++) {
        Long imageId = 0l;
        try {
          imageId = Long.parseLong(imageIds[j]);
        } catch (NumberFormatException e) {
          addFieldError("imageIds", Messages.getString("numberIdError"));
          return INPUT;
        }

        Image image = new Image();
        image = imageService.get(imageId);
        if (image == null) {
          addFieldError("imageIds", Messages.getString("wrongIdError"));
          return INPUT;
        }

        for (int i = 0; i < cust.getImageOfList().size(); i++) {
          if (cust.getImageOfList().get(i).getId() == image.getId()) {
            cust.getImageOfList().remove(i);
            imageService.delete(image);
            FileUtils.deleteQuietly(new File(filePath + "\\" + image.getName()));
            FileUtils.deleteQuietly(new File(filePathd + "\\" + image.getName()));
          }
        }
        session.put("imageList", cust.getImageOfList());
      }
      return SUCCESS;
    } catch (Exception e) {
      addFieldError("exception", Messages.getString("somethingWrong"));
      return ERROR;
    }
  }