fileUpload problem
foxpv Apr 10, 2008 4:55 PMHi guys,
Im tryng to implement richfaces file upload and I get one error.
When the file comes in my bean, the byte array of my file is null, but the FileName is OK!
heres my configuration,
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>InventarioServicos</display-name> <!-- SPRING --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</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>facelets.REFRESH_PERIOD</param-name> <param-value>2</param-value> </context-param> <context-param> <param-name>facelets.LIBRARIES</param-name> <param-value> /WEB-INF/facelettl.xml </param-value> </context-param> <!-- <context-param> <param-name>org.richfaces.LoadStyleStrategy</param-name> <param-value>NONE</param-value> </context-param> --> <context-param> <param-name>org.ajax4jsf.SKIN</param-name> <param-value>mcpInventario</param-value> </context-param> <filter> <filter-name>jpaFilter</filter-name> <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> </filter> <filter> <display-name>Ajax4jsf Filter</display-name> <filter-name>ajax4jsf</filter-name> <filter-class>org.ajax4jsf.Filter</filter-class> <init-param> <param-name>createTempFiles</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>maxRequestSize</param-name> <param-value>20000000</param-value> </init-param> </filter> <filter-mapping> <filter-name>jpaFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>ajax4jsf</filter-name> <servlet-name>FacesServlet</servlet-name> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <servlet> <servlet-name>FacesServlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>FacesServlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>FacesServlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <login-config> <auth-method>BASIC</auth-method> </login-config> </web-app>
my xhtml:
<rich:fileUpload fileUploadListener="#{formulario.listenerUpload}" maxFilesQuantity="1" uploadData="#{formulario.files}" listWidth="200px" listHeight="100px" reRender="painelUpload" id="upload" > <a4j:support event="onuploadcomplete" reRender="info" /> </rich:fileUpload>
and my bean:
public void listenerUpload(UploadEvent event) throws IOException{ UploadItem item = event.getUploadItem(); Upload.upload(item.getFileName(), item.getData()); File f = new File("asd"); System.out.println("File : '" + item.getFileName() + "' was uploaded"); /*if (item.isFile()) { File file = item.getFile(); System.out.println("Absolute Path : '" + file.getAbsolutePath() + "'!"); } else { ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write(item.getData()); System.out.println(b.toString()); }*/ }
somebody can help me?
I lost all day tryng to solve this problem :(
tranks.. and sorry for the bad english