3 Replies Latest reply on Feb 9, 2009 3:01 PM by Thomas Marcon

    rich:fileUpload returns

    Thomas Marcon Newbie

      I have a rich:fileUpload component in one of my pages, I want my users to be able to upload a CSV file to the server. Here is the page source :

      <a4j:outputPanel id="ajxBlackList_19">
       <h:inputText id="property_BLACK_LIST" value="#{eventCreation.currentEvent.blackList}" />
      </a4j:outputPanel>
      
      <h:outputText id="houtputText_24" value="Charger les valeurs via un fichier CSV :" />
      <rich:fileUpload id="black_list_upload" fileUploadListener="#{eventCreation.listener}" listHeight="200" immediateUpload="false" acceptedTypes="csv,txt">
       <a4j:support id="a4jsupport_27" event="onuploadcomplete" reRender="ajxBlackList_19" />
       </rich:fileUpload>
      <h:message id="hmessage_29" tooltip="true" for="black_list_upload" style="color: red;" />
      


      And here is the code of my bean listener (which is never called) :

       private UploadItem csvItem;
      
       [...]
      
       public synchronized void listener(UploadEvent event) {
      
       this.setCsvItem( event.getUploadItem() );
      
       // retrieve component id for later use
       UIComponent fromComponent = event.getComponent();
       String componentId = fromComponent.getId();
      
       String content = null;
      
       // file reading
       if (getCsvItem().isTempFile()) {
       File csvFile = getCsvItem().getFile();
       StringBuilder fileData = new StringBuilder();
      
       try {
      
       BufferedReader reader = new BufferedReader(new FileReader(csvFile));
       char[] buf = new char[1024];
       int numRead=0;
      
       while((numRead=reader.read(buf)) != -1){
       fileData.append(buf, 0, numRead);
       }
      
       reader.close();
      
       } catch(Exception e) {
       addErrorMessage(e.getMessage(), componentId);
       return;
       }
       content = fileData.toString();
      
       } else {
       content = new String(getCsvItem().getData());
       }
       this.getCurrentEvent().getProperty(DrawingLotsEvent.PROPERTY_WHITE_LIST).setValue(content);
      
       }
      
      


      Every time I try to upload a file, I get an instant error "Transfer error occured" without my listener being called. I have no trace of any error in a4j log window.

      I put this in my web.xml as suggested :

       <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>true</param-value>
       </init-param>
       <init-param>
       <param-name>maxRequestSize</param-name>
       <param-value>1000000</param-value>
       </init-param>
       </filter>
      


      Anyone has any idea ? Or maybe a way to debug this component so I could know WHY this error occurs ?

      Thanks a lot.