13 Replies Latest reply on Apr 18, 2008 1:11 PM by Jon Welzel

    rich:fileUpload Issues

    Jon Welzel Newbie

      Hi everyone.
      Before u all tell me to look at previous posts addressing this issue I'd like to say that I've been looking through this forum for a few days now and all the different topics raised here in search for help. Not just looking but trying all those tips on my project, everything to no avail though.
      So I decided to create this topic, hoping someone will be able to help me :D

      For starters, I basically copied the example available in the JBoss code sample trunk (http://anonsvn.jboss.org/repos/richfaces/trunk/samples/)

      Here's my bean:

      package beans;
      
      import java.io.ByteArrayOutputStream;
      import java.io.File;
      import java.util.ArrayList;
      import java.util.List;
      
      import org.richfaces.event.UploadEvent;
      import org.richfaces.model.UploadItem;
      
      public class uploadMB {
      
       private List itens = new ArrayList();
      
       public List getItens() {
       if (itens == null) {
       itens = new ArrayList();
       }
       return itens;
       }
      
       public void setItens(List itens) {
       this.itens = itens;
       }
      
       public void upload(UploadEvent event) {
       UploadItem item = event.getUploadItem();
       System.out.println("Arquivo : '" + item.getFileName() + "' foi enviado");
       if (item.isFile()) {
       File file = item.getFile();
       itens.add(file);
       System.out.println("Para o diretório : '" + file.getPath() + "'!");
       }
       else {
       ByteArrayOutputStream b = new ByteArrayOutputStream();
       b.write(item.getData());
       System.out.println(b.toString());
       }
       }
      }
      


      Here's my index.xhtml:
      
      <!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:a4j="http://richfaces.org/a4j"
       xmlns:rich="http://richfaces.org/rich"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core">
      <link rel="stylesheet" type="text/css" href="css/theme.css" />
      
      <style>
      .top {
       vertical-align: top;
      }
      .info {
       height: 208px;
       overflow: auto;
      }
      </style>
      
      <h:form enctype="multipart/form-data" >
       <h:panelGrid columns="2" columnClasses="top, top">
       <rich:fileUpload id="upload1"
       fileUploadListener="#{uploadMB.upload}"
       uploadData="#{uploadMB.itens}"
       addControlLabel="Adicionar"
       clearAllControlLabel="Limpar tudo"
       clearControlLabel="Limpar"
       maxFilesQuantity="5"
       reRender="table"
       uploadControlLabel="Enviar"
       immediateUpload="false"
       stopEntryControlLabel="Parar"
       acceptedTypes="jpg, gif, png, bmp, rar, zip, exe, doc"
       autoclear="false"
       stopControlLabel="Parar">
       <f:facet name="label">
       <h:outputText value="{_KB}KB de {KB}KB enviados --- {mm}:{ss}" />
       </f:facet>
       <a4j:support event="onuploadcomplete" reRender="info" />
       </rich:fileUpload>
      
       <h:panelGroup id="info">
       <rich:panel bodyClass="info">
       <f:facet name="header">
       <h:outputText value="Informacoes" />
       </f:facet>
       <rich:columnGroup>
       <h:column>
       <h:outputText styleClass="headerText" value="Arquivo" />
       </h:column>
       <h:column>
       <h:outputText styleClass="headerText" value="Tamanho" />
       </h:column>
       </rich:columnGroup>
      
       <h:column>
       <h:outputText value="#{item.fileName}" />
       </h:column>
       <h:column>
       <h:outputText value="#{item.file.length}" />
       </h:column>
      
       </rich:panel>
      
       </h:panelGroup>
      
       </h:panelGrid>
      
      </h:form>
      </html>
      


      And here's my web.xml:
      
      <?xml version="1.0"?>
      <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
       <description>Facelets StarterKit</description>
       <display-name>Teste2</display-name>
       <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.DEVELOPMENT</param-name>
       <param-value>true</param-value>
       </context-param>
       <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>client</param-value>
       </context-param>
       <context-param>
       <param-name>com.sun.faces.validateXml</param-name>
       <param-value>true</param-value>
       </context-param>
       <context-param>
       <param-name>com.sun.faces.verifyObjects</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>
      
       <filter>
       <display-name>RichFaces Filter</display-name>
       <filter-name>richfaces</filter-name>
       <filter-class>org.ajax4jsf.Filter</filter-class>
       <init-param>
       <param-name>createTempFiles</param-name>
       <param-value>true</param-value>
       </init-param>
       <init-param>
       <param-name>maxRequestSize</param-name>
       <param-value>10000000</param-value>
       </init-param>
       </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>
      
      <filter>
       <display-name>Sleep Filter</display-name>
       <filter-name>sleepFilter</filter-name>
       <filter-class>filters.SleepDemoFilter</filter-class>
      </filter>
      <filter-mapping>
       <filter-name>sleepFilter</filter-name>
       <servlet-name>Faces Servlet</servlet-name>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
       <dispatcher>ERROR</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>*.jsf</url-pattern>
      </servlet-mapping>
      
      <login-config>
       <auth-method>BASIC</auth-method>
      </login-config>
      </web-app>
      


      Here are my problems:
      1-My app won't work outside my IDE, if I try running this example from my browser the upload just doesn't happen.

      2-I've been trying to find a way to specify a directory inside my app server (tomcat 5.5) to where the uploaded temp files (fileName.upload) can be saved, so they're stored on my server even after it's shut down. Haven't found a way to do that yet, if u guys could enlighten me, I'd be very glad =]

      I just started messing with JSF and its implementations so be easy on me k? :P

      Thx in advance!