I am trying to get a PrimeFaces multiple file uploader working on a JSF page and have been given the following requirements (non-negotiable!) by my tech lead:
- Must be a PrimeFaces/JSF page called
imageUpload.jsf
- Must deploy to a WAR and deployed on Tomcat (
v7.0.19
) - Must use the following PrimeFaces/JSF JARs (they're "enterprise architecture standards"):
jsf-api.jar
andjsf-impl.jar
from JSF 2.0.3, andprimefaces-2.2.1.jar
My first task is to just replicate what that linked demo page has - just a simple JSF page that contains the file upload component on it. So I created an Eclipse project, created what I believe to be the correct directory structure and configuration files, used Ant to WAR it up, and deployed to Tomcat's webapps directory. When I go to localhost:8080/imageUpload.jsf
, I get a 404 (The requested resource (/imageUpload.jsf) is not available.) error.
Here's my setup:
Project directory structure in eclipse:
ImageUploader
src/
com.company.imgupload.FileUploadController.java
build/ --> where java compiles to and then copies over to WEB-INF/classes/
dist/ --> where image-uploader.war gets WARed to
lib/ --> copied to WEB-INF/lib/
war/
META-INF/
MANIFEST.MF
WEB-INF/
classes/
lib/
imageUpload.xhtml
faces-config.xml
web.xml
The FileUploadController.java
is the same as what the PrimeFaces people have on the demo link provided above - again I'm just trying to get this simple example working before I start to customize it for what we need.
web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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" >
<welcome-file-list>
<welcome-file>imageUpload.jsf</welcome-file>
</welcome-file-list>
<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>
</web-app>
faces-config.xml
:
<?xml version="1.0" encoding="utf-8"?>
<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_0.xsd" version="2.0">
<!-- Not using MangedBean declarations for this simple example -->
</faces-config>
imageUpload.xhtml
:
<html xmlns="http://www.w3c.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<link type="text/css" rel="stylesheet" href="themes/bluesky/skin.css" />
</h:head>
<h:body>
<center>
<p:panel header="Multiple File Uploader Demo" style="width: 350;">
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}" mode="advanced" update="messages" multiple="true" sizeLimit="100000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
<p:growl id="messages" showDetail="true"/>
</h:form>
</p:panel>
<div><h:messages ></h:messages></div>
</center>
</h:body>
</html>
For reiteration, these are placed in the following WAR file:
image-uploader.war/
META-INF/
MANFIEST.MF
WEB-INF/
classes/
com/company/imgupload/FileUploadController.java
lib/
jsf-api.jar (v2.0.3)
jsf-impl.jar (v2.0.3)
primefaces-2.2.1.jar
web.xml
faces-config.xml
imageUpload.xhtml
This war is then deployed to ${CATALINA.HOME}/webapps/
. When I run Tomcat, I don't get any errors or warnings in the logs, but I do see this in catalina.<date>.log
(I'm on Windows 7):
Apr 11, 2012 2:31:33 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive image-uploader.war
Apr 11, 2012 2:31:34 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.0.3 (FCS b03) for context '/image-uploader'
Apr 11, 2012 2:31:34 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
Am I missing any other configuration files here? Do I need to have a imageUpload.jsf
on top of (or instead of) imageUpload.xhtml
?
What explains this 404 error I'm getting?!? Thanks in advance.
NOTE: Unless it is impossible to get PrimeFaces/JSF working under the JAR versions I've indicated, please just respect that I don't have any say-so over what our standards are. If I can prove that JSF 2.0.3 is incompatible with PrimeFaces 2.2.1, then I can probably convince the technical brass to change standards. But unless I can prove that, these are the versions and technologies I'm stuck with - so please don't clutter SO with "why would you choose that technology"- or "why would you use an old version"-type responses!
Edit:
Changed my web.xml
to reflect @Luigi's suggestion, and (per @Matt's suggestion) pointed my browser at localhost:8080/image-uploader/imageUploader.jsf
and am not getting an HTTP 500 error:
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/image-uploader] threw exception [javax/servlet/jsp/jstl/core/Config] with root cause
java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:340)
at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:150)
...etc.
Does this mean anything to anyone?