简体   繁体   中英

Primefaces fileUpload is not called

I am using primefaces 5.0 and jsf 2.2 and I keep getting a NullPointer error.

.xhtml file:

<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:

<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. 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. I also tried it without the commons fileupload.

I think your allowTypes value is breaking the component. allowTypes expects a regular expression. Try allowTypes="/(\\.|\\/)(gif|jpe?g|png)$/"

The problem was with the primefaces version. Primefaces 6.1 works just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM