file upload problems
simoncigoj Apr 13, 2008 11:59 AMI'm trying tu use richfaces file upload component with myfaces, and when I upload the file nothing happens...I putted a brakepoint in the listener but it looks like that the listener is not invoked...so the listener does not fire.
Below I posted my code and the settings of my environment, can anyone help me because this file upload looks realy cool and I would like to use it.
My code
public class UploadHandler { public void fileUploadListener(org.richfaces.event.UploadEvent event) { if(event==null){ System.out.println("null upload event"); return; } UploadItem item = event.getUploadItem(); String name = "unnamed_attachment"; byte[] data = item.getData(); if (item.isFile()) { name = item.getFileName(); data = item.getData(); File file = item.getFile(); System.out.println( "uploaded "+name+ " - length= "+( (data==null)?0:data.length) + " tmpFile="+file.getAbsoluteFile() ); } } }
faces file:
<!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"> <h:form enctype="multipart/form-data"> <rich:fileUpload id="upload" fileUploadListener="#{uploadHandler.fileUploadListener}" maxFilesQuantity="2"> <f:facet name="label"> <h:outputText value="{_KB}KB from {KB}KB uploaded {mm}:{ss}" /> </f:facet> </rich:fileUpload> </h:form> </html>
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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>FileUploadJSF</display-name> <context-param> <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name> <param-value>com.sun.facelets.FaceletViewHandler</param-value> </context-param> <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> <context-param> <param-name>org.apache.myfaces.USE_ENCRYPTION</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>org.apache.myfaces.ERROR_HANDLING</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name> <param-value>false</param-value> </context-param> <listener> <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> </listener> <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> <welcome-file-list> <welcome-file>index.faces</welcome-file> </welcome-file-list> <context-param> <param-name>facelets.LIBRARIES</param-name> <param-value> /WEB-INF/facelets/customTags/customTags.taglib.xml; /WEB-INF/facelets/editView/editView.taglib.xml </param-value> </context-param> <!-- Ajax4JSF filter mora biti definiran pred vsemi drugimi filtri --> <filter> <display-name>Ajax4jsf Filter</display-name> <filter-name>ajax4jsf</filter-name> <filter-class>org.ajax4jsf.Filter</filter-class> <init-param> <param-name>forceparser</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>maxRequestSize</param-name> <param-value>20000000</param-value> </init-param> </filter> <filter-mapping> <filter-name>ajax4jsf</filter-name> <servlet-name>Faces Servlet</servlet-name> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <filter> <filter-name>MyFacesExtensionsFilter</filter-name> <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class> </filter> <!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) --> <filter-mapping> <filter-name>MyFacesExtensionsFilter</filter-name> <url-pattern>/faces/myFacesExtensionResource/*</url-pattern> </filter-mapping> <!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages --> <filter-mapping> <filter-name>MyFacesExtensionsFilter</filter-name> <servlet-name>Faces Servlet</servlet-name> </filter-mapping> <!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages --> <filter-mapping> <filter-name>MyFacesExtensionsFilter</filter-name> <url-pattern>*.jsf</url-pattern> </filter-mapping> </web-app>
my faces.config.xml
<?xml version="1.0" encoding="UTF-8"?> <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xi="http://www.w3.org/2001/XInclude" 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_1_2.xsd"> <managed-bean> <managed-bean-name> uploadHandler</managed-bean-name> <managed-bean-class> upload.UploadHandler</managed-bean-class> <managed-bean-scope> request</managed-bean-scope> </managed-bean> <application> <locale-config> <default-locale>en</default-locale> </locale-config> </application> </faces-config>