Foren

PrimeFaces FileUpload not working after update from 4.0 to 6.1

Yeray Rodríguez, geändert vor 6 Jahren.

PrimeFaces FileUpload not working after update from 4.0 to 6.1

New Member Beiträge: 5 Beitrittsdatum: 02.03.15 Neueste Beiträge
Hi,

I'm trying to update an application from PrimeFaces 4 to 6.1 and everything works fine except <p:fileUpload>, the managedBean doesn't get the file, the setter is not invoked. I've prepared a very simple portlet to show the problem.

Common environment:
- Liferay 6.2.3 CE GA4
- Java 6 (saddly is mandatory)
- ANT
- Servlet 3.0
- JSF 2.1
- Tomcat 7 bundle

web.xml content
<!--?xml version="1.0"?-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
	<distributable />
	<context-param>
		<param-name>com.sun.faces.expressionFactory</param-name>
		<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
	</context-param>
	<context-param>
		<param-name>javax.faces.PROJECT_STAGE</param-name>
		<param-value>Development</param-value>
	</context-param>
	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
</web-app>

faces-config.xml
<!--?xml version="1.0"?-->
<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd" version="2.1">
	<lifecycle>
		<phase-listener>com.liferay.faces.util.lifecycle.DebugPhaseListener
		</phase-listener>
	</lifecycle>
</faces-config>

view.xhtml
<!--?xml version="1.0"?-->
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets">
	<h:head />
	<h:body>
		<h:form enctype="multipart/form-data" prependid="false">
			<p:inputtext value="#{form.text}"></p:inputtext>
			<p:fileupload value="#{form.file}" mode="simple" skinSimple="true" />
			<p:commandbutton value="Submit" ajax="false" actionListener="#{form.processUpload}" />
		</h:form>
	</h:body>
</f:view>

Managed Bean: Form.java
package myform;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.model.UploadedFile;
import com.liferay.faces.util.logging.Logger;
import com.liferay.faces.util.logging.LoggerFactory;

@ManagedBean
@SessionScoped
public class Form implements Serializable {

	private static final long serialVersionUID = 1143936750298959291L;
	private static Logger logger = LoggerFactory.getLogger (Form.class);

	private UploadedFile file;
	private String text;

	public UploadedFile getFile ( ) {
		return file;
	}

	public void setFile (UploadedFile file) {
		this.file = file;
	}

	public String getText ( ) {
		return text;
	}


	public void setText (String text) {
		this.text = text;
	}

	public void processUpload ( ) {
		logger.info ("Text: " + text);
		if (file != null) {
			logger.info ("Uploaded file: " + file.getFileName ( ));
		} else {
			logger.info ("Uploaded file: empty");
		}
	}
}

Dependencies of working portlet - PrimeFaces 4 (Included in lib directory, ivy or maven are not allowed):
- commons-fileupload-1.2.2.jar
- commons-io-1.3.2.jar
- jboss-el-2.0.0.GA.jar
- jsf-api-2.1.21.jar
- jsf-impl-2.1.21.jar
- liferay-faces-alloy-3.2.4-ga5.jar
- liferay-faces-bridge-api-3.2.4-ga5.jar
- liferay-faces-bridge-impl-3.2.4-ga5.jar
- liferay-faces-util-3.2.4-ga5.jar
- primefaces-4.0.jar


To update the portlet dependencies I have followed this documentation: LIFERAY FACES VERSION SCHEME and Liferay Faces

Dependencies of not working portlet - PrimeFaces 6 (Included in lib directory, ivy or maven are not allowed):
- com.liferay.faces.bridge.api-3.1.0.jar
- com.liferay.faces.bridge.ext-2.0.1.jar
- com.liferay.faces.bridge.impl-3.1.0.jar
- com.liferay.faces.util-2.1.0.jar
- commons-fileupload-1.3.1.jar
- commons-io-2.4.jar
- javax.faces-2.1.29-09.jar
- javax.faces-api-2.1.jar
- jboss-el-2.0.0.GA.jar
- primefaces-6.1.jar


I've also tried to update to JSF 2.2 with no success and I've tried different configurations on web.xml and faces-config.xml but I think is not necessary to add any aditional configuration.
Any idea? Thanks.

P.S: I have attached both portlets
thumbnail
Vernon Singleton, geändert vor 6 Jahren.

RE: PrimeFaces FileUpload not working after update from 4.0 to 6.1

Expert Beiträge: 315 Beitrittsdatum: 14.01.13 Neueste Beiträge
Hello Yeray,

Yeray Rodríguez:

Dependencies of not working portlet - PrimeFaces 6 (Included in lib directory, ivy or maven are not allowed):
- com.liferay.faces.bridge.api-3.1.0.jar
- com.liferay.faces.bridge.ext-2.0.1.jar
- com.liferay.faces.bridge.impl-3.1.0.jar
- com.liferay.faces.util-2.1.0.jar
- commons-fileupload-1.3.1.jar
- commons-io-2.4.jar
- javax.faces-2.1.29-09.jar
- javax.faces-api-2.1.jar
- jboss-el-2.0.0.GA.jar
- primefaces-6.1.jar


I just tried the primefaces demo from our last release, and the file upload is working just fine on Liferay 6.2 GA4. Here are the jars in its WEB-INF/lib:
com.liferay.faces.alloy-2.0.1.jar
com.liferay.faces.bridge.api-3.1.0.jar
com.liferay.faces.bridge.ext-2.0.1.jar
com.liferay.faces.bridge.impl-3.1.0.jar
com.liferay.faces.util-2.1.0.jar
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
javax.faces-2.1.29-09.jar
log4j-1.2.14.jar
primefaces-6.1.jar

Notice that the demo does not need the faces-api jar. Maybe that is part of your issue.

Yeray Rodríguez:
I've also tried to update to JSF 2.2 with no success and I've tried different configurations on web.xml and faces-config.xml but I think is not necessary to add any aditional configuration.


Here below, you can also see the dependencies which I have pulled from the portlet at www.liferayfaces.org, and they are a bit different from what you have listed ... note that the faces-api jar is listed as "provided" ... that may be part of your problem:
<dependencies>
    <dependency>
        <groupid>commons-fileupload</groupid>
        <artifactid>commons-fileupload</artifactid>
        <version>1.3.1</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupid>commons-io</groupid>
        <artifactid>commons-io</artifactid>
        <version>2.4</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupid>javax.faces</groupid>
        <artifactid>javax.faces-api</artifactid>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupid>org.glassfish</groupid>
        <artifactid>javax.faces</artifactid>
        <version>2.1.29-09</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupid>com.liferay.faces</groupid>
        <artifactid>com.liferay.faces.bridge.ext</artifactid>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupid>com.liferay.faces</groupid>
        <artifactid>com.liferay.faces.bridge.impl</artifactid>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupid>log4j</groupid>
        <artifactid>log4j</artifactid>
        <version>1.2.14</version>
    </dependency>
    <dependency>
        <groupid>org.primefaces</groupid>
        <artifactid>primefaces</artifactid>
        <version>6.1</version>
    </dependency>
</dependencies>


Also, you can get all of the source code for our working primefaces 6.1 demo here in the sources jars, or here on github.

Hope that helps.
Yeray Rodríguez, geändert vor 6 Jahren.

RE: PrimeFaces FileUpload not working after update from 4.0 to 6.1

New Member Beiträge: 5 Beitrittsdatum: 02.03.15 Neueste Beiträge
Vernon Singleton:
Hello Yeray,

Yeray Rodríguez:

Dependencies of not working portlet - PrimeFaces 6 (Included in lib directory, ivy or maven are not allowed):
- com.liferay.faces.bridge.api-3.1.0.jar
- com.liferay.faces.bridge.ext-2.0.1.jar
- com.liferay.faces.bridge.impl-3.1.0.jar
- com.liferay.faces.util-2.1.0.jar
- commons-fileupload-1.3.1.jar
- commons-io-2.4.jar
- javax.faces-2.1.29-09.jar
- javax.faces-api-2.1.jar
- jboss-el-2.0.0.GA.jar
- primefaces-6.1.jar


I just tried the primefaces demo from our last release, and the file upload is working just fine on Liferay 6.2 GA4. Here are the jars in its WEB-INF/lib:
com.liferay.faces.alloy-2.0.1.jar
com.liferay.faces.bridge.api-3.1.0.jar
com.liferay.faces.bridge.ext-2.0.1.jar
com.liferay.faces.bridge.impl-3.1.0.jar
com.liferay.faces.util-2.1.0.jar
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
javax.faces-2.1.29-09.jar
log4j-1.2.14.jar
primefaces-6.1.jar

Notice that the demo does not need the faces-api jar. Maybe that is part of your issue.

Yeray Rodríguez:
I've also tried to update to JSF 2.2 with no success and I've tried different configurations on web.xml and faces-config.xml but I think is not necessary to add any aditional configuration.


Here below, you can also see the dependencies which I have pulled from the portlet at www.liferayfaces.org, and they are a bit different from what you have listed ... note that the faces-api jar is listed as "provided" ... that may be part of your problem:
<dependencies>
    <dependency>
        <groupid>commons-fileupload</groupid>
        <artifactid>commons-fileupload</artifactid>
        <version>1.3.1</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupid>commons-io</groupid>
        <artifactid>commons-io</artifactid>
        <version>2.4</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupid>javax.faces</groupid>
        <artifactid>javax.faces-api</artifactid>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupid>org.glassfish</groupid>
        <artifactid>javax.faces</artifactid>
        <version>2.1.29-09</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupid>com.liferay.faces</groupid>
        <artifactid>com.liferay.faces.bridge.ext</artifactid>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupid>com.liferay.faces</groupid>
        <artifactid>com.liferay.faces.bridge.impl</artifactid>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupid>log4j</groupid>
        <artifactid>log4j</artifactid>
        <version>1.2.14</version>
    </dependency>
    <dependency>
        <groupid>org.primefaces</groupid>
        <artifactid>primefaces</artifactid>
        <version>6.1</version>
    </dependency>
</dependencies>


Also, you can get all of the source code for our working primefaces 6.1 demo here in the sources jars, or here on github.

Hope that helps.


Hello Vernon, and thanks,

I've changed the jars but without success. I've also tried to changed to servlet 2.5 and i've also changed UploadFile to DefaultUploadFile.

Finally I decided to copy working code from primefaces demo. After some tests, I realized the problem only happens when I use p:fileUpload with mode="simple". It works ok with mode="advanced" using ajax. Unfortunately, this portlet is not allowed to use Ajax.

I've updated the code of the example with 2 forms: using simple mode and advanced mode, and I've attached the new code.

Thanks!!

view.xhtml
<!--?xml version="1.0"?-->
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui">
	<h:head />
	<h:body>
		<h:form enctype="multipart/form-data">
			<p:inputtext value="#{formSimple.text}"></p:inputtext>
			<br>
			<p:fileupload value="#{formSimple.file}" mode="simple" skinSimple="true" />
			<p:commandbutton value="Submit" ajax="false" actionListener="#{formSimple.processUpload}" />
		</h:form>
		<br>
		<br>
		<h:form enctype="multipart/form-data">
			<p:inputtext value="#{formAdvanced.text}"></p:inputtext>
			<br>
			<p:fileupload fileUploadListener="#{formAdvanced.handleFileUpload}" mode="advanced" multiple="false" auto="true" />
			<p:commandbutton value="Submit" ajax="false" actionListener="#{formAdvanced.processUpload}" />
		</h:form>
	</h:body>
</f:view>


FormSimple.java
package myform;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.model.UploadedFile;
import com.liferay.faces.util.logging.Logger;
import com.liferay.faces.util.logging.LoggerFactory;

@ManagedBean
@SessionScoped
public class FormSimple implements Serializable {

	private static final long serialVersionUID = 1143936750298959291L;
	private static Logger logger = LoggerFactory.getLogger (FormSimple.class);

	private UploadedFile file;
	private String text;

	public UploadedFile getFile ( ) {
		return file;
	}

	public void setFile (UploadedFile file) {
		this.file = file;
	}

	public String getText ( ) {
		return text;
	}


	public void setText (String text) {
		this.text = text;
	}

	public void processUpload ( ) {
		logger.info ("Text: " + text);
		if (file != null) {
			logger.info ("Uploaded file: " + file.getFileName ( ));
		} else {
			logger.info ("Uploaded file: empty");
		}
	}
}


FormAdvanced.java
package myform;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;
import com.liferay.faces.util.logging.Logger;
import com.liferay.faces.util.logging.LoggerFactory;

@ManagedBean
@SessionScoped
public class FormAdvanced implements Serializable {

	private static final long serialVersionUID = 1143936750298959291L;
	private static Logger logger = LoggerFactory.getLogger (FormAdvanced.class);

	private UploadedFile file;
	private String text;

	public UploadedFile getFile ( ) {
		return file;
	}

	public void setFile (UploadedFile file) {
		this.file = file;
	}

	public String getText ( ) {
		return text;
	}

	public void setText (String text) {
		this.text = text;
	}

	public void processUpload ( ) {
		logger.info ("Text: " + text);
		if (file != null) {
			logger.info ("Uploaded file: " + file.getFileName ( ));
		} else {
			logger.info ("Uploaded file: empty");
		}
	}

	public void handleFileUpload (FileUploadEvent event) {
		setFile (event.getFile ( ));
		logger.info ("handleFileUpload - Received fileName=[" + getFile ( ).getFileName ( ) + "]");
	}
}
thumbnail
Vernon Singleton, geändert vor 6 Jahren.

RE: PrimeFaces FileUpload not working after update from 4.0 to 6.1

Expert Beiträge: 315 Beitrittsdatum: 14.01.13 Neueste Beiträge
Hi Yeray,

I have opened a ticket for your issue. You can watch the issue to see if we can get it fixed for you.
https://issues.liferay.com/browse/FACES-3250

- Vernon
Yeray Rodríguez, geändert vor 6 Jahren.

RE: PrimeFaces FileUpload not working after update from 4.0 to 6.1

New Member Beiträge: 5 Beitrittsdatum: 02.03.15 Neueste Beiträge
Vernon Singleton:
Hi Yeray,

I have opened a ticket for your issue. You can watch the issue to see if we can get it fixed for you.
https://issues.liferay.com/browse/FACES-3250

- Vernon


Hi Vernon,

for now I've upgraded the application to JSF2.2 to be able to use h:inputFile as a workaround.

Thank you.
thumbnail
Vernon Singleton, geändert vor 6 Jahren.

RE: PrimeFaces FileUpload not working after update from 4.0 to 6.1

Expert Beiträge: 315 Beitrittsdatum: 14.01.13 Neueste Beiträge
Yeray Rodríguez:
for now I've upgraded the application to JSF2.2 to be able to use h:inputFile as a workaround.

Glad you were able to find a work around.