0

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 and jsf-impl.jar from JSF 2.0.3, and primefaces-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?

Community
  • 1
  • 1
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
  • in your web.xml, change "*.jsf" to "*.xhtml" – Luiggi Mendoza Apr 11 '12 at 20:06
  • Genius! Does that mean I could also just rename my file to imageUpload.jsf (instead of imageUpload.xhtml)? – IAmYourFaja Apr 11 '12 at 20:43
  • The *.jsf filter was heavily used in JSF 1.X for the JSP pages because a *.jsp filter will cause a self-reference error, that doesn't mean that your pages should have JSF extension. In JSF 2.x this was no more a problem and you could use the *.jsp filter. If your have XHTML pages, your filter should be *.XHTML. – Luiggi Mendoza Apr 11 '12 at 21:00
  • I'll recommend you read [difference between XHTML and JSP for JSF](http://stackoverflow.com/questions/7914660/what-is-the-difference-between-creating-xhtml-or-jsp-or-jsf-for-jsf-pages) – Luiggi Mendoza Apr 11 '12 at 21:02
  • Made the change and am now getting an HTTP 500 error (please see my edit for details). – IAmYourFaja Apr 12 '12 at 11:48
  • Quick search on SO with results such as http://stackoverflow.com/questions/15113628/java-lang-classnotfoundexception-javax-servlet-jsp-jstl-core-config suggests you are missing jstl.jar. – Danubian Sailor Feb 17 '14 at 15:12
  • A bit odd, because JSTL isn't even referenced in the posted XHTML content :/ I think there is a mistake in the config somewhere still, that com.sun.faces.application.view.JspViewHandlingStrategy in the stacktrace seems to be hinting that the JSP view handler is used in stead of facelets. – Gimby Mar 20 '14 at 09:48
  • The XHTML file should be in the root directory of the web-app given the URL you're using to access it, and certainly not in the WEb-INF folder, where it is invisible to browsers. – user207421 Jul 01 '15 at 06:08

1 Answers1

0

First of all be aware that the Primefaces showcase shows the most recent Primefaces release version. You should check in the Primefaces documentation for version 2.2.1 if the file upload is possible with all the given attributes.

Then (as mentioned by Luigi) you have to make sure that the faces servlet mapping in your web.xml will match with your files in the project.

Finally to your request URL. I am not using Tomcat, but in Glassfish you have a context root where your application is deployed to. The context root needs to be a part of your urls and is normally the same as your war files name (you can change it, but I don't know where to do it for Tomcat).

So assuming that the context root is the same as your war file name, you should try:

localhost:8080/image-uploader/imageUpload.jsf
Matt Handy
  • 29,855
  • 2
  • 89
  • 112
  • Thank you for the helpful answer @Matt! But still having issues, please see my edit to the OP. Thanks again! – IAmYourFaja Apr 12 '12 at 11:50
  • It seems that you did not include all required classes for JSF. See [here](http://www.mkyong.com/jsf2/java-lang-classnotfoundexception-javax-servlet-jsp-jstl-core-config/) – Matt Handy Apr 12 '12 at 12:02
  • Ha! I found the same link, redeployed with `javax.servlet.jsp.jstl-1.2.1.jar` (and confirmed its there under `WEB-INF/lib/`) and still the same error... – IAmYourFaja Apr 12 '12 at 12:07