RichFaces fileUpload无法调用侦听器

时间:2013-02-20 14:58:21

标签: java file-upload jsf-2 richfaces

对于<rich:fileUpload>,我无法调用listener。当我检查firebug控制台时,我发现它进入无限GET个请求循环。

的web.xml:

<context-param>
    <param-name>org.richfaces.fileUpload.maxRequestSize</param-name>
    <param-value>1000000000</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.fileUpload.createTempFiles</param-name>
    <param-value>false</param-value>
</context-param>

的facelet:

    <h:form enctype="multipart/form-data">
        <rich:fileUpload fileUploadListener="#{fileUploadController.listener}" id="upload" acceptedTypes="jpg, gif, png, bmp"
                ontyperejected="alert('Only JPG, GIF, PNG and BMP files are accepted');" maxFilesQuantity="5">
                <a4j:ajax event="uploadcomplete" execute="@none" render="info" />
        </rich:fileUpload>
    </h:form>

支持Bean:

public void listener(FileUploadEvent event) throws Exception{
UploadedFile item = event.getUploadedFile();
uploadFile.setLength(item.getData().length);
uploadFile.setName(item.getName());
uploadFile.setData(item.getData());
writeFile();
}

public void writeFile() {  

FileOutputStream fop = null;  
File file;
try {

    file = new File(fPath + uploadFile.getName());
    logger.info(fPath + uploadFile.getName());

    fop = new FileOutputStream(file);  
    if (!file.exists()) {  
        file.createNewFile();  
    }  

    fop.write(uploadFile.getData());  
    fop.flush();  
    fop.close();    

} catch (IOException e) {  
    e.printStackTrace();  

} finally {  
    try {  
        if (fop != null) {  
            fop.close();  
        }  
    } catch (IOException e) {  
        e.printStackTrace();  
    }  
}  

我查了很多类似的问题,但没有任何线索!

我正在使用RichFaces版本4.2.2

1 个答案:

答案 0 :(得分:1)

您可以尝试从web.xml中删除以下行, 有人通过这样做来解决。

<filter>
  <filter-name>Seam Multipart Filter</filter-name>
  <filter-class>org.jboss.seam.web.MultipartFilter</filter-class>
</filter>

<filter-mapping>
  <filter-name>Seam Multipart Filter</filter-name>
  <url-pattern>*.seam</url-pattern>
</filter-mapping>