[英]Primefaces fileUpload is not called
I am using primefaces 5.0 and jsf 2.2 and I keep getting a NullPointer error. 我正在使用primefaces 5.0和jsf 2.2,并且不断收到NullPointer错误。
.xhtml file: .xhtml文件:
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{mBKnjiga.uploadSlike}" mode="advanced" allowTypes="*.jpg;*.png;*.gif;" />
Bean: 豆角,扁豆:
byte[] image;
...
public void uploadSlike(FileUploadEvent event) throws IOException {
image = IOUtils.toByteArray(event.getFile().getInputstream());
}
web.xhtml: web.xhtml:
<filter>
<filter-name>primeFacesFileUploadFilter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>primeFacesFileUploadFilter</filter-name>
<servlet-name>FacesServlet</servlet-name>
</filter-mapping>
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto</param-value>
</context-param>
I have added the jars for commons-io and commons-fileupload just in case. 为了防万一,我为commons-io和commons-fileupload添加了jar。 Also I have tried to upload the picture using the mode="simple" the way it was explained in their showcase but it didn't work.
我也尝试过使用模式=“ simple”上传图片,就像他们在展示柜中解释的那样,但是没有用。 I also tried it without the commons fileupload.
我也尝试了没有commons fileupload的情况。
I think your allowTypes
value is breaking the component. 我认为您的
allowTypes
值正在破坏组件。 allowTypes
expects a regular expression. allowTypes
需要一个正则表达式。 Try allowTypes="/(\\.|\\/)(gif|jpe?g|png)$/"
尝试
allowTypes="/(\\.|\\/)(gif|jpe?g|png)$/"
The problem was with the primefaces version. 问题出在primefaces版本上。 Primefaces 6.1 works just fine.
Primefaces 6.1可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.