Primefaces p:fileupload component problem - jsf

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.

Related

Primefaces resources are not loaded

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>

RichFaces and facelets combination not working

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.

Primefaces 5 fileUpload handler not called [duplicate]

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.

How to separate head?

Here how look my .jspx files:
<?xml version='1.0' encoding='utf-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jsp/jstl/core">
<jsp:output omit-xml-declaration="true" doctype-root-element="HTML" doctype-system="http://www.w3.org/TR/html5"/>
<jsp:directive.page contentType="text/html;charset=utf-8"/>
<f:loadBundle basename="my.pack.resource" var="r"/>
<f:loadBundle basename="my.pack.error" var="e"/>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html utf-8"/>
<meta name="viewport" content="width=device-width"/>
<title> Some title </title>
<jsp:directive.include file="/temp/myLayout.jspf" />
</head>
<body>
<h:form>
<h:commandLink .........
</h:form>
</body>
</html>
</f:view>
</jsp:root>
In order to keep my view files clear and small
I would like to put all above and after body in
templates and include it in my .ispx files and pass title as parameter.
If anybody knows solution, please help.
EDIT
I have changed my view from .jspx to .xhtml, but my servlet filters now don't work.
Here my web.xml:
<?xml version = '1.0' encoding = 'windows-1252'?>
<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_2_5.xsd"
version="2.5">
<context-param>
<param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
<param-value>*.xhtml;*.jsf</param-value>
</context-param>
<filter>
<filter-name>loginFilter</filter-name>
<filter-class>my.pack.filterpack.LoginFilter</filter-class>
</filter>
<filter>
<filter-name>remebermefilter</filter-name>
<filter-class>my.pack.filterpack.RemeberMeFilter</filter-class>
</filter>
<filter>
<filter-name>NoCacheFilter</filter-name>
<filter-class>my.pack.filterpack.NoCacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>loginFilter</filter-name>
<url-pattern>/view/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>remebermefilter</filter-name>
<url-pattern>/login/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>NoCacheFilter</filter-name>
<url-pattern>*.xhtml</url-pattern>
<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 mappings -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<error-page>
<error-code>500</error-code>
<location>/index.jsp</location>
</error-page>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/viewExp.jsp</location>
</error-page>
<listener>
<listener-class>my.pack.timer.MyJobManager</listener-class>
</listener>
</web-app>
This is one of the reasons why JSP(X) is abandoned, deprecated and succeeded by Facelets 4 years ago. JSP(X) doesn't offer easy templating capabilities in order to achieve this kind of requirements.
Just migrate to Facelets. Rename .jspx to .xhtml and replace <jsp:xxx> tags by <ui:xxx> tags. Your functional requirement is answered in 2nd example of How to include another XHTML in XHTML using JSF 2.0 Facelets?
Facelets is natively available in JSF 2.x. If you're still using JSF 1.x, then you can just install it separately as per its documentation.

Primefaces FileUpload event not firing - JSF 2.0

I have posted my question on the Primefaces forum but no one has responded so I figured I would try here.
I have been attempting to get fileUpload to work for some time now. I am currently running the RC2 build with mojarra 2.0.3 and Tomcat 7.
I have a dialog which will contain the fileUpload component like so.
<p:dialog id="uploadFileDialog" >
<h:form id="uplaodFileForm" prependId="false" enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{fileUploadController.uploadFile} auto="true"/>
</h:form>
</p:dialog>
The fileUploadController looks like this
public class FileUploadController {
public void uploadFile(FileUploadEvent event) {
byte[] file = event.getFile().getContents();
System.out.println("MADE IT INTO FILE UPLOAD !!! ");
}
}
For some reason when the file is uploaded it never triggers the fileUploadEvent and it never gets into the controller. The upload looks like its working, the flash part renders and gives the impression its doing something but no backing bean is ever being called. I can seem to figure out what I am doing wrong and I have read just about every post on uploading a file using primefaces. Anyone know what I am doing wrong?
java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream
PrimeFaces fileupload uses Apache Commons FileUpload under the covers which in turn has another dependency, the Apache Commons IO. Ensure that you've both JAR's in your /WEB-INF/lib.
Update: as per the comments, you also need to ensure that the upload filter is been declared in web.xml as per the users' guide:
<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 also need to ensure that there are no other filters before in the web.xml which may be reading the HttpServletRequest#getInputStream(), because it can be read only once.
I have also experienced a similar problem. The fix for me (using a Maven project) was to add the following dependencies in the pom.xml file:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
This is the equivalent of having the corresponding .jar files in your WEB-INF/lib, so try do that if this is not a Maven project.
that is correct you must add
<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 later this
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
aditionaly if your using maven add this dependencies
<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>
<dependency>
<groupId>portlet-api</groupId>
<artifactId>portlet-api</artifactId>
<version>1.0</version>
</dependency>
i think i have solved your problem.
Check on your web.xml the presence of:
<context-param>
<param-name>com.sun.faces.enableViewStateIdRendering</param-name>
<param-value>false</param-value>
</context-param>
You must delete this option or set it do True (the default value).
I have the same issue, I have solved it by adding
<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>
like BalusC said.
but adding this :
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Because by default in J2EE 6 this part is optional JSF 2.0 Servlet activates automatically when the WEB-INF/faces-config.xml descriptor is present.
But it necessary to active correctly PrimeFaces Filter
Jboss 6.1.0.Final / PrimeFaces 3.0.RC2
In Websphere 7 the event is fired because when I select file and press upload I can see bar to upload that grow up.
The problem is that in Websphere 7 I suppose that there are a filter that consume HttpRequest and when arrive to event listener is just consumed so don't have data :(
No message are present in log the debugging is very complicate. Exists some trace or logger to enable in JSF 2 Mojarra 2 and PrimeFaces 3.4.2?

Resources