本帖最后由 purple 于 2013-1-30 17:59 编辑
Q:怎么使用脚本删除平台中使用“文件上传”控件上传的文件。
A:1.在/obpm/src/main/java/cn/myapps/core/dynaform/document/ejb/Document.java中添加如下方法:- /**
- * 删除上传文件
- *
- * @return
- * @throws Exception
- */
- public void doDeleteFile(String fileFullName) {
- try {
- if (!StringUtil.isBlank(fileFullName)) {
- fileFullName = URLDecoder.decode(fileFullName,"UTF-8");
- UploadProcess uploadProcess = (UploadProcess) ProcessFactory.createRuntimeProcess(UploadProcess.class, this.applicationid);
- String[] fileFullNameArry = fileFullName.split(";");
- for (int i = 0; i < fileFullNameArry.length; i++) {
- UploadVO uploadVO = (UploadVO) uploadProcess.findByColumnName1("PATH", fileFullNameArry[i]);
- if (uploadVO != null) {
- String fileRealPath = Environment.getInstance().getRealPath(uploadVO.getPath());
- File file = new File(fileRealPath);
- if (file.exists()) {
- if (!file.delete()) {
- Log.warn("File(" + fileRealPath + ") delete failed");
- throw new Exception("File(" + fileRealPath + ") delete failed");
- }
- }
- uploadProcess.doRemove(uploadVO.getId());
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
复制代码 2.把文件上传控件的属性页面的刷新勾选上,然后插入一个按钮,类型选择无,同时勾选上刷新选项,在动作执行后脚本中写入下面代码:- var currentDocument = getCurrentDocument();
- var field = currentDocument .findItem("文件上传");
- currentDocument .doDeleteFile(field.getValue());
- field .setValue("");
复制代码 详情见附图:
|