FileUploadListener not invoke FileUploadEvent

UI Components for JSF
Post Reply
ntapan
Posts: 13
Joined: 02 Sep 2015, 16:35

09 Nov 2018, 09:49

Hi,

I'm using primefaces 6.2.3 with apollo theme 2.0.1, tomcat 9.0 and java 9, spring and security 5.0.5

I want to add fileUpload to my xhtml page, but it does not call fileuploadlistener method from bean class.


Here is xhtml:

Code: Select all

<p:fileUpload
	fileUploadListener="#{myBean.handleFileUpload}"
	mode="advanced" auto="true"
	sizeLimit="100000" allowTypes="/(\.|\/)(csv|doc)$/" />
and added multipart to form:

Code: Select all

<h:form id="formAddWorkout" enctype="multipart/form-data" >


Method in BeanClass:

Code: Select all

public void handleFileUpload(FileUploadEvent event) {
		System.out.println("FİLE UPLOAD Started");
	}

I have also checked in forums, and I have added below codes to my web.xml.
I have tried with and without <dispatcher>FORWARD</dispatcher>, but result does not change.
web.xml:

Code: Select all

 <filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
<!--     <dispatcher>FORWARD</dispatcher> -->
</filter-mapping>


Here is other config parts of my web.xml:

Code: Select all

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
<context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
  </context-param>

I have also changed META-INF/context.xml, and added below line:

Code: Select all

<Context allowCasualMultipartParsing="true">
    </Context>

Unfortunately, none of them changed the result.

I'm using fileUpload in my other project, java8, tomcat 8.5, primefaces 6.1.8 , apollo 1.0.3, and it works spring 4.2.0 and spring security 4.0.2
And it works fine.
I could not find any reason that causes not invoke fileuploadlistener.

Any idea, will be very helpful

Thanks,

ntapan
Posts: 13
Joined: 02 Sep 2015, 16:35

12 Nov 2018, 15:23

Hi,

I have solved the issue.
The solution is NOT to use commons-fileupload, use native options.

1- I have deleted "commons-fileupload.jar" from library
2- I have REMOVED below code from web.xml:
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<!-- <dispatcher>REQUEST</dispatcher> -->
</filter-mapping>
3- I have ADDED below code to web.xml:
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>native</param-value>
</context-param>


After these changes, it works.

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

13 Nov 2018, 17:44

Thanks for the feedback! Appreciated

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

09 Dec 2020, 14:37

I think the real solution is here: viewtopic.php?t=24077
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 53 guests