This question already has answers here:
How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null / throws an error / not usable
(11 answers)
Closed 8 years ago.
I'm developing a Web Project with JSF and PrimeFaces 5.0. Although there are many forums about this problem I can't find the solution with the FileUpload. The issue is that when I Uplaod a file handler method is never invoked
This is my code:
HTML page:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/WEB-INF/templates/template.xhtml">
<ui:define name="content">
<f:view>
<p:panel id="panel" header="Registros de Fuente" style="width:100%;">
<h:form enctype="multipart-data">
<p:fileUpload fileUploadListener="#{registrosBean.handleFileUpload}"
required="true" mode="advanced" dragDropSupport="false"
multiple="true" sizeLimit="1000000" fileLimit="5" update="messages"
allowTypes="/(\.|\/)(gif|jpe?g|png|pdf|doc|docx)$/">
</p:fileUpload>
</h:form>
<h:form enctype="multipart/form-data">
<p:fileUpload value="#{registrosBean.file}" mode="simple" />
<p:commandButton value="Submit" ajax="false"/>
</h:form>
</p:panel>
</f:view>
</ui:define>
</ui:composition>
</html>
BEAN:
#Component("registrosBean")
#ViewScoped
#ManagedBean
public class RegistroBean extends GenericBean<Registrofuente> implements Serializable {
public void handleFileUpload(FileUploadEvent event) {
System.out.println("SOME CONSOLE MESSAGE");
}
public void cogerArchivos( ) {
System.out.println("SOME CONSOLE MESSAGE");
}
public UploadedFile file;
/**
* #return the file
*/
public UploadedFile getFile() {
return file;
}
/**
* #param file the file to set
*/
public void setFile(UploadedFile file) {
System.out.println("SOME CONSOLE MESSAGE");
this.file = file;
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>UNAC</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application-context.xml</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>aristo</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>pages/login.jsf</welcome-file>
</welcome-file-list>
<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>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>10240</param-value> <!-- 10 Mb -->
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<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>*.xhtml</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>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>
Some aditional information about my project
JSF 2.1
IDE: Eclipse
Jboss 7.1
It's important to say that I've already added the commons-io and commons-fileupload libraries to the WEB-INF\lib folder
I've been many days and consulted many forums about this issue and I can not find the solution, any suggestion will help. Thank you
try to simplify the filter on web.xml first. Try this.
<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>
</filter-mapping>
And you don't need those commons-io libs on WEB-INF\lib since you are using PF5 already. Remove them.
Related
I'm using Primefaces 5.3 with TomEE, but I when I access my pages the PF resources are not being loaded and I get the following error:
$ is not defined
PrimeFaces is not defined
Even when I access the resource URL I get the following error
URL:
http://localhost:8080/Myapp/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo
Error:
XML Parsing Error: no root element found Location: http://localhost:8080/Myapp/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo Line Number 1, Column 1
My page :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
<f:view>
<p:growl id="notificationMessage" showDetail="true" />
<p:panel id="basic" header="Basic" footer="Movie Details" style="margin-bottom:20px">
<h:panelGrid columns="1" cellpadding="10">
<p:outputLabel for="mbbData" value="Data Value: " />
<p:inputText id="mbbData" value="#{mbbDataInputController.mbbData}" required="true" />
<p:commandButton action="#{mbbDataInputController.addMbb}" />
</h:panelGrid>
</p:panel>
</f:view>
</html>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID"
version="3.0">
<display-name>my-service</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>
WEB-INF/faces-config.xml
</param-value>
</context-param>
<!-- Faces Servlet -->
<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>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>rest-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.huawei.myapp.service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
I also tried to add the following to the page head:
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
but it did not work.
Also please note that as I debugged the PrimeResourceHandler class, the resource are being created and the resource path is in the right jar.
OK, I found the problem and the solution as follows.
Problem:
The problem is that I am using two servlets, javax.faces.webapp.FacesServlet for JSF and org.glassfish.jersey.servlet.ServletContainer for REST web services. and when I requested reource file, actually Jersey servlet were going to serve it for me not the faces servlet.
Solution:
I changed the web.xml url mapping as:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/javax.faces.resources/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>rest-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
I am using RichFaces and jsf 2.but when I moved to facelets some of
the rich component doesnt works for me. I am using
richfaces-api-3.3.4.Final.jar,
richfaces-impl-jsf2-3.3.4.Final.jar,
richfaces-ui-3.3.4.Final.jar.
tomcat version is 7.0.23
netbeans 7.3.1
I have configured the following details in web.xml
<web-app version="3.0" 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">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>
facelets.RECREATE_VALUE_EXPRESSION_ON_BUILD_BEFORE_RESTORE
</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
<param-value>*.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<!-- Making the RichFaces skin spread to standard HTML controls -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<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>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
faces-config.xml
<application>
<view-handler>org.ajax4jsf.application.AjaxViewHandler</view-handler>
</application>
index.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition>
<h:form id="studentFormId" binding="#{StudentDetail.initForm}">
<rich:panel id="Student" >
<f:facet name="header">
<h:outputText value="Student DOB" />
<rich:calender/>
</f:facet>
</rich:panel>
</h:form>
</ui:composition>
</html>
When I deploy after clean and build it shows the following error.
SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.
config.ConfigureListener java.lang.RuntimeException: com.sun.faces.config.ConfigurationException:
CONFIGURATION FAILED! Must have aConstructor that takes in a ComponentConfig
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:273)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4765)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5260)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:866)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:842)
Caused by: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Must have a Constructor that takes in a ComponentConfig at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:449) at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:214)
... 43 more
Caused by: javax.faces.view.facelets.FaceletException: Must have a Constructor that takes in a ComponentConfig
at com.sun.faces.facelets.tag.AbstractTagLibrary$UserComponentHandlerFactory.<init> (AbstractTagLibrary.java:330)
at com.sun.faces.facelets.tag.AbstractTagLibrary.addComponent(AbstractTagLibrary.java:558)
at com.sun.faces.facelets.tag.TagLibraryImpl.putComponent(TagLibraryImpl.java:114)
at com.sun.faces.config.processor.FaceletTaglibConfigProcessor.processComponent(FaceletTaglibConfigProcessor.java:588)
at com.sun.faces.config.processor.FaceletTaglibConfigProcessor.processTags (FaceletTaglibConfigProcessor.java:368)
at com.sun.faces.config.processor.FaceletTaglibConfigProcessor.processTagLibrary(FaceletTaglibConfigProcessor.java:321)
at com.sun.faces.config.processor.FaceletTaglibConfigProcessor.process(FaceletTaglibConfigProcessor.java:270)
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:437)
... 44 more
Caused by: java.lang.NoSuchMethodException:org.richfaces.taglib.AjaxValidatorHandler.<init> (javax.faces.view.facelets.ComponentConfig)
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getConstructor(Class.java:1657)
at com.sun.faces.facelets.tag.AbstractTagLibrary$UserComponentHandlerFactory.<init>(AbstractTagLibrary.java:328)
... 51 more
Can anybody find what mistake I have done here?
RichFaces 3.x and JSF 2 works fine. I'm using JSF 2.2 and RichFaces 3.3.4.Final.
You need to disable built-in JSF 2 facelets and add dependency on old jsf-facelets 1.1.15 (as per https://developer.jboss.org/wiki/RichFaces333andJSF20).
However, keep in mind that Mojarra has a bug when it looks for DISABLE_FACELET_JSF_VIEWHANDLER instead of javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER as per specification.
I'm trying to upload file using simple fileuploader but I keep getting this error:
org.apache.tomcat.util.http.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>40960</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/home/alen/uploads</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>bootstrap</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>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
XHTML:
<h:form enctype="multipart/form-data">
<h:panelGrid columns="1" style="width:100%;" class="imageUploadTable">
<p:fileUpload value="#{objave.file}" mode="simple"/>
<f:facet name="footer">
<p:commandButton actionListener="#{objave.spremiSliku()}"
value="Spremi"
icon="ui-icon-disk"
ajax="false"/>
</f:facet>
</h:panelGrid>
</h:form>
Objave.java
private UploadedFile file;
public String spremiSliku() {
System.out.println(file.getFileName());
return "";
}
If I use advanced fileUploader then everything is ok, but I need simple fileUploader, and can't get it to work. I'm PrimeFaces noob so I don't know how to fix this. Can some help me with this?
I'm having some problems with PrettyFaces on the pages I use <p:fileupload>.
When I disable the PrettyFaces filter on the page, everything works just fine. When I put it back, I can see the HTTP traffic on the webbrowser, but my fileupload handler is never fired.
This is some relevant part of the code.
Any help would be appreciated!
My .xhtml
<h:form id="formImportarSNs" enctype="multipart/form-data">
<p:fieldset legend="Admin Panel">
<p:fileUpload value="#{adminPanelBean.file}" mode="simple"/>
<p:commandButton ajax="false" actionListener="#{adminPanelBean.upload}" value="confirm" />
</p:fieldset>
</h:form>
My backingBean
package br.sgrd.bean;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.model.UploadedFile;
#ViewScoped
#ManagedBean
public class AdminPanelBean{
private UploadedFile file;
public void upload() {
if(arquivo != null) {
FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
// getters/setters/etc
}
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>GRD</display-name>
<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>
<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>
<url-pattern>/*</url-pattern>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
</web-app>
My pretty-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config- prettyfaces.xsd">
<url-mapping id="admin_panel">
<pattern value="/admin_panel" />
<view-id value="/faces/xhtml/admin_panel.xhtml" />
</url-mapping>
</pretty-config>
Edit: Cleaned up some code.
I've found the solution.
Create the context.xml in the META-INF folder and put this code:
<?xml version="1.0" encoding="UTF-8"?>
<Context allowCasualMultipartParsing="true">
</Context>
You can remove the Fileupload Filter from web.xml
Where I found the solution: http://ocpsoft.org/rewrite/docs/faq
And that's why you need to put it: How to use HttpServletRequest#getParts() in a servlet filter running on Tomcat?
If your problem is the size of the file, take a look at: <p:fileUpload> limiting to 2 Mb
It does not work very well. Works with upload small files. If the file is a few MB he can not invoke the method. I do not advise using Primefaces + prettyfaces.
If your case is upload small files can work. Remove the primefaces fileupload configuration of web.xml and create the context.xml file as mentioned above.
I did with 'rewrite-servlet-2.0.9.Final.jar'. It worked perfectly with upload small files.
Use in 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>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
I am using Primefaces 2.0.1 but the FileUpload component is not working properly. It uses JQuery uploadify behind the scenes. This is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
<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>
</filter-mapping>
<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>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
</web-app>
This is my index.xhtml :-
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form prependId="false">
<h:commandButton actionListener="#{NewJSFManagedBean.add}" value="add"/>
<p:fileUpload auto="false" widgetVar="fileUpl" fileUploadListener="#{NewJSFManagedBean.saveFile}"/>
</h:form>
</h:body>
</html>
I have following libraries in my classpath :-
primefaces 2.0.1
commons-beanutils
commons-beanutils-bean-collection
commons-digestor
commons-fileUpload
commons-io
commons-logging
jhighlight
The file gets correctly uploaded in /tmp but in browser it always says HTTP error. Please help me. It used to work till yesterday. But today i did a fresh installation of Glassfish and it has stopped working.
A filter needs to be added to web.xml. So, add these lines to web.xml
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/tmp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
To be able to use the Primefaces fileUpload component, a few Apache Commons dependencies also need to be added:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
I have had some troubles with this component also. I seem to remember that by adding an id to the fileUpload component and/or the form, things started working for me. Worth a try.
i think you are missing enctype="multipart/form-data" in your h:form tag.
I had the same problem. And note that by deleting the cookies from my browser-firefox-and going to upload my application and it worked.
I'm using PRIMEFACES 2.2.1 and the problem is still there: HTTP error when Chrome or Firefox is used; all fine with IE. In my case, this apparently happens due to a reverse proxy shielding the actual server running the application. If the application is used through a direct URL reference (http://server:port/some path), it works fine; if the reverse proxy URL is used, the requests fail. I don't know why this fails in FF and GC and doesn't do so in IE.