多文件上传不适用于jsf 1.1.15和richfaces 3.3.3

时间:2014-06-17 13:41:17

标签: jsf

我正在尝试使用richfaces 3.3.3在JSF中实现多个文件上传但是监听器根本没有被调用

jsf page

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
     xmlns:ui="http://java.sun.com/jsf/facelets"
     xmlns:h="http://java.sun.com/jsf/html"
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:a4j="http://richfaces.org/a4j"
     xmlns:rich="http://richfaces.org/rich">

    <style>
 .top {
     vertical-align: top;

 } 
 .info {
     height: 100px;
     overflow: auto;
 }
 </style>
 <h:form id="docUpld" enctype="multipart/form-data"> 
         <h:panelGrid columns="2" columnClasses="top,top"> 
             <rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
                uploadData="#{fileUploadBean.files}"  
                 maxFilesQuantity="20"
                 id="upload"
                 immediateUpload="false" allowFlash="true">
                 <a4j:support event="onuploadcomplete" limitToList="true"  /> 
             </rich:fileUpload>

         </h:panelGrid> 
     </h:form> 
 </ui:composition>

我的豆子

package WFMTJavaResources;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import WFMTJavaResources.File;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="fileUploadBean")
@SessionScoped
public class FileUploadBean implements java.io.Serializable{
private static final long serialVersionUID = 1L;
    private ArrayList<File> files = new ArrayList<File>();
    private int uploadsAvailable = 5;
    private boolean autoUpload = false;
    private boolean useFlash = true;
    public int getSize() {
        if (getFiles().size()>0){
            return getFiles().size();
        }else 
        {
            return 0;
        }
    }

   public FileUploadBean() {
    }

   public void paint(OutputStream stream, Object object) throws IOException {
        stream.write(getFiles().get((Integer)object).getData());
    }
    public void listener(UploadEvent event) throws Exception{
        UploadItem item = event.getUploadItem();
        File file = new File();
        file.setLength(item.getData().length);
        file.setName(item.getFileName());
        file.setData(item.getData());
        files.add(file);
        uploadsAvailable--;
    }  

    public String clearUploadData() {
        files.clear();
        setUploadsAvailable(5);
        return null;
    }

    public long getTimeStamp(){
        return System.currentTimeMillis();
    }

    public ArrayList<File> getFiles() {
        return files;
    }

   public void setFiles(ArrayList<File> files) { 
        this.files = files;
    }

   public int getUploadsAvailable() {
        return uploadsAvailable;
    }

   public void setUploadsAvailable(int uploadsAvailable) {
        this.uploadsAvailable = uploadsAvailable;
    }

   public boolean isAutoUpload() {
        return autoUpload;
    }

   public void setAutoUpload(boolean autoUpload) {
        this.autoUpload = autoUpload;
    }

   public boolean isUseFlash() {
        return useFlash;
    }

   public void setUseFlash(boolean useFlash) {
        this.useFlash = useFlash;
    }

}

File.java

package WFMTJavaResources;

public class File 
{

    private String Name;
    private byte[] data;

    public String getName() {
        return Name;
    }
    public void setName(String name) {
        Name = name;
    }
    public byte[] getData() {
        return data;
    }
    public void setData(byte[] data) {
        this.data = data;
    }


 }

听众不会开火。请帮我找出它出错的地方?

0 个答案:

没有答案