当前位置:首页 > 开发 > Web前端 > 前端 > 正文

richfaces 4 fileUpload组件删除上传的文件

发表于: 2014-08-23   作者:sunjing   来源:转载   浏览:
摘要:  页面代码               <h:form id="fileForm">            <rich:

 页面代码      

        <h:form id="fileForm">
            <rich:fileUpload fileUploadListener="#{fileUploadBean.listener}" id="upload"
                             onclear="clearFile(event);"/>
        </h:form>

        <a4j:jsFunction name="removeFile" action="#{fileUploadBean.clearFile}">
            <a4j:param name="filename" assignTo="#{fileUploadBean.filename}"/>
        </a4j:jsFunction>

        <h:outputScript>
            var clearFile = function (event) {
                var data = event.rf.data;
                for (var i in data) {
                    var item = data[i];
                    removeFile(item.name);
                }
            }
        </h:outputScript>

 

Managed Bean 代码

public class FileUploadBean {
    private Map<String, UploadedImage> files = new HashMap<>();

    private String filename;

    public void listener(FileUploadEvent event) throws Exception {
        UploadedFile item = event.getUploadedFile();
        UploadedImage file = new UploadedImage();
        file.setLength(item.getData().length);
        file.setName(item.getName());
        file.setData(item.getData());
        files.put(item.getName(), file);
    }

    public void clearFile() {
        files.remove(filename);
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public static class UploadedImage implements Serializable {
        private static final long serialVersionUID = -8192553629588066292L;
        private String name;
        private long length;
        private byte[] data;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public long getLength() {
            return length;
        }

        public void setLength(long length) {
            this.length = length;
        }

        public byte[] getData() {
            return data;
        }

        public void setData(byte[] data) {
            this.data = data;
        }
    }
}

richfaces 4 fileUpload组件删除上传的文件

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号