RichFaces的fileupload和NullPointerException [英] RichFaces fileupload and NullPointerException

查看:179
本文介绍了RichFaces的fileupload和NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用rich:fileUpload上传文件到服务器,这里是代码:

  @Name( fileUploader)
public class FileUploader {

private byte [] fileData;

public void uploadFileListener(UploadEvent uploadEvent){
fileData = uploadEvent.getUploadItem()。getData();
//其他代码


code $ $ $ $ $ $ $ $ $

页面包含如下:

  rich:fileUpload fileUploadListener =#{fileUploader.uploadFileListener}

我得到的是uploadEvent包含文件名,大小等等的数据...但是
uploadEvent.getUploadItem()。getData();

返回null ...


我已经见过类似的问题这里 ...但没有答案...

谢谢!

解决方案

您是否在组件xml中配置了multipart-filter?



类似这样:

 < web:multipart-filter create-temp-files =truemax-request-size =1000000url-pattern =*。seam/> 

更新:我不完全确定这是否用于s :fileUpload或rich:fileUpload。在考虑这个配置之前,请检查下面的代码。默认情况下,如果我没有记错,你应该使用临时文件,这是我认为的RichFaces的默认配置。对不起,但我没有我的项目来检查它。



如果你像上面那样配置它,你的文件将被保存到一个临时文件(create-temp在这种情况下,您应该使用

  uploadEvent.getUploadItem()。getFile )

您可以检查它是否存储在一个文件中:

  uploadEvent.getUploadItem()。isTempFile()

既然你说文件元数据在那里,这看起来是个问题,你只是在错误的地方寻找你的数据:)



我还记得上传控件(rich:upload)需要的东西(不完全确定)在h:form里面

希望有帮助。


I'm trying to upload file to the server using rich:fileUpload, here's the code:

@Name("fileUploader")
public class FileUploader {

private byte[] fileData;

    public void uploadFileListener(UploadEvent uploadEvent) {
        fileData = uploadEvent.getUploadItem().getData();
        //other code here
    }   
}

page contains the following :

rich:fileUpload fileUploadListener="#{fileUploader.uploadFileListener}"

What I'm getting is that uploadEvent contains data about file name, size and so on... but
uploadEvent.getUploadItem().getData();
returns null...

I've already seen similar issue here... but there's no answer...

Thanks!

解决方案

Did you configured multipart-filter in components xml?

Something like this:

<web:multipart-filter create-temp-files="true" max-request-size="1000000" url-pattern="*.seam"/>

Update: I'm not completely sure if this is used for s:fileUpload or rich:fileUpload. Please check the code bellow before thinking about this configuration. By default, if I remember correctly, you should be using temp files which is the default configuration for RichFaces I think. Sorry but I don't have my project here to check it.

If you have it configured like the above your file will be saved to a temporary file (create-temp-files="true"), in this case you should access your data by using

uploadEvent.getUploadItem().getFile()

You can check if it is stored in a file with:

uploadEvent.getUploadItem().isTempFile()

Since you say that the file "metadata" is there, this looks to be the problem, you are just looking for your data in the wrong place :)

If you have it configured to false, your method should work.

Also I remember something (not completely sure) that the upload control (rich:upload) needed to be inside an h:form

Hope it helps.

这篇关于RichFaces的fileupload和NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆