Exemplo n.º 1
0
  public String upload() throws Exception {
    // 1. 解析得到 Workbook 对象
    InputStream inp = new FileInputStream(file);
    Workbook wb = WorkbookFactory.create(inp);

    // 2. 调用 Service 方法上传数据到数据库服务器
    List<UploadError> uploadErrors = employeeService.upload(wb);

    // 3. 若验证没有通过: 上述方法有返回值. 返回值为
    if (uploadErrors.size() > 0) {
      // 4. 获取 i18n 中的错误消息, 并把所有的错误消息都加到 actionErrors 中.
      for (UploadError ue : uploadErrors) {
        String fileName = ue.fieldName;
        int rowNumber = ue.rowNumber;

        String errorMesssage =
            getText("errors.fileupload", new String[] {rowNumber + "", fileName});
        addActionError(errorMesssage);
      }

      // 5. 返回 upload-input 页面
      return "upload-input";
    }

    return "upload-success";
  }
Exemplo n.º 2
0
 public void prepareSave() {
   if (id == null) model = new Employee();
   else {
     model = employeeService.get(id);
     model.getRoles().clear();
   }
 }
Exemplo n.º 3
0
 public void prepareInput() {
   if (id != null) {
     model = employeeService.get(id);
     if (model == null) {
       throw new InvalidPageException("页面不存在");
     }
   }
 }
Exemplo n.º 4
0
  // ajax 检验指定的 Employee 是否为 Manager
  public String ajaxValidateManager() {
    if (employeeService.isManager(id)) {
      inputStream = new ByteArrayInputStream("1".getBytes());
    } else {
      delete();
      inputStream = new ByteArrayInputStream("0".getBytes());
    }

    return "ajax-success";
  }
Exemplo n.º 5
0
  // ajax 检验 loginName 是否可用
  public String ajaxValidateLoginName() {
    String loginName = model.getLoginName();
    try {
      employeeService.login(loginName, "");
    } catch (EmployeeNotExitException e) {
      inputStream = new ByteArrayInputStream("1".getBytes());
    } catch (NotMatchPasswordException e) {
      inputStream = new ByteArrayInputStream("0".getBytes());
    }

    return "ajax-success";
  }
Exemplo n.º 6
0
  public String uploadTemplateDownload() throws IOException {
    // 1. 调用 Service 方法, 获取 Excel 文档对应的 Workbook 对象
    Workbook workbook = employeeService.buildUploadExcelWorkbook();
    // 2. 先写到一个指定的位置
    String fileName =
        ServletActionContext.getServletContext()
            .getRealPath("/files/" + System.currentTimeMillis() + ".xls");
    workbook.write(new FileOutputStream(fileName));

    // 3. 确定输入流
    inputStream = new FileInputStream(fileName);
    this.contentType = "application/vnd.ms-excel";
    this.contentLength = inputStream.available();
    this.contentDisposition = "attachment;filename=employees.xls";

    return "download-success";
  }
Exemplo n.º 7
0
  public String validateLoginName() {

    if (oldLoginName.equals(model.getLoginName())) {
      return "success";
    }

    // 验证 loginName 是否可用
    String loginName = model.getLoginName();
    try {
      employeeService.login(loginName, "");
    } catch (EmployeeNotExitException e) {
      // 用户名可用.
      return "success";
    } catch (NotMatchPasswordException e) {
      addFieldError("loginName", getText("errors.loginname.invalid"));
      return "save-input";
    }

    return null;
  }
Exemplo n.º 8
0
  public String save() {
    String result = validateLoginName();

    employeeService.save(model);
    return result;
  }
Exemplo n.º 9
0
 public String list() {
   employeeService.getPage(page);
   return "list";
 }
Exemplo n.º 10
0
 public void delete() {
   employeeService.delete(id);
 }