title: JSF 1.2 and richfaces 3.3.3 Final <rich:fileUpload Transfer error occurred
body: <p>I don't want to persist immediately, but actually put in session and just after the user clicks on the "Upload and assign to Order" button I will start really persisting. 
  some how neithe rin Chrome nor in Firefox comes the attachment add event, 
  and later 
  "Upload and assign to Order" button has everything null causing exception.</p>
  
  <p></p>
  
  <pre><code>&lt;body&gt;
  &lt;h:form id="uploadFormId" enctype="multipart/form-data"&gt;
      &lt;rich:messages id="messages" style="font-weight:bold; color: DarkBlue; " /&gt;
  
      &lt;h:panelGroup id="panelGroupId"&gt;
          &lt;h:outputText value="Upload New Attachment"  style="font-weight:bold" /&gt;
          &lt;br /&gt;&lt;br /&gt;
  
          &lt;h:outputText value="Doc Id" /&gt;
          &lt;h:inputText id="DOCID" label="Doc Id:" value="#{uploadBean.docId}" required="true" style="margin-left: 10pt;"
                       validatorMessage="Doc Id must be an integer number." &gt;
              &lt;!-- &lt;f:validateLength minimum="5" maximum="20" /&gt; --&gt;
              &lt;!-- &lt;f:validateRegex pattern="^\d+$" /&gt; only in JSF 2.0 --&gt;
          &lt;/h:inputText&gt;
           &lt;h:message for="DOCID" errorClass="error" /&gt;
          &lt;br /&gt;
  
          &lt;h:outputText value="Language" /&gt;
          &lt;h:selectOneMenu value="#{uploadBean.language}"&gt;
              &lt;f:selectItems value="#{uploadBean.languageOptions}"/&gt;
          &lt;/h:selectOneMenu&gt;
  
          &lt;h:selectBooleanCheckbox id="defaultness_Checkbox"  title="defaultness_Checkbox"  value="#{uploadBean.defaultness}" style="margin-left: 10pt;" /&gt;
          &lt;h:outputText value="Is Default?" style="margin-left: 2pt;" /&gt;
          &lt;br /&gt;&lt;br /&gt;
      &lt;/h:panelGroup&gt;
  
      &lt;h:outputText value="Attachment" for="richFileUploadId" /&gt;
      &lt;rich:fileUpload id="richFileUploadId"
                       acceptedTypes="pdf" 
                       fileUploadListener="#{uploadBean.fileUploadListener}" 
                       immediateUpload="true" 
      &gt;
      &lt;/rich:fileUpload&gt;
      &lt;!--
      &lt;rich:fileUpload id="richFileUploadId"
                       acceptedTypes="pdf" 
                       fileUploadListener="#{uploadBean.fileUploadListener}" 
                       immediateUpload="true" 
                       listHeight="50px" listWidth="300px" 
                       allowFlash="false"
                       addControlLabel="Add file..." clearAllControlLabel="Clear all" clearControlLabel="Clear"
                       stopEntryControlLabel="Stop process" uploadControlLabel="Upload file" 
      &gt;
          &lt;a4j:support event="onuploadcomplete" 
                       process="panelGroupId" 
                       render="attachmentUploadTableId, messages"
                       reRender="attachmentUploadTableId, messages"    
          /&gt;
          &lt;f:facet name="label"&gt;
              &lt;h:outputText value="{_KB}KB from {KB}KB uploaded - {mm}:{ss}" /&gt;
          &lt;/f:facet&gt;
      &lt;/rich:fileUpload&gt;
      --&gt;
      &lt;br /&gt;&lt;br /&gt;
  
  
  &lt;!--  reRender="attachmentUploadTableId, " --&gt;
  &lt;!--  addControlLabel="Add file..." clearAllControlLabel="Clear all" clearControlLabel="Clear"
                       stopEntryControlLabel="Stop process" uploadControlLabel="Upload file"  --&gt;
      &lt;a4j:commandLink reRender="attachmentUploadTableId, messages" 
                      process="panelGroupId"
                      value="Upload and assign to order"
                      action="#{uploadBean.uploadAssignToOrder}" 
                      style="  border: 1px solid #999;
                          padding:1px 4px 1px 4px;
                          color: #333;
                          background-color: #e7e7e7;
                          text-decoration: none;
                          margin-right: 10px;
                          display: inline;
                          cursor:pointer; "&gt;
      &lt;/a4j:commandLink&gt;
      &lt;br /&gt;&lt;br /&gt;
  
      &lt;h:outputText value="Current Attachments" for="attachmentUploadTableId" style="font-weight: bold; " /&gt;
  
      &lt;rich:dataTable id="attachmentUploadTableId" value="#{uploadBean.fileList}" var="file"&gt;
          &lt;rich:column style="width: 50px; " &gt;
              &lt;f:facet name="header"&gt;
                  &lt;h:outputLabel value="File Name" /&gt;
              &lt;/f:facet&gt;
              &lt;h:outputText value="#{file.filename}          " /&gt;
          &lt;/rich:column&gt;
          &lt;rich:column style="width: 30px; " &gt;
              &lt;f:facet name="header"&gt;
                  &lt;h:outputLabel value="Language" /&gt;
              &lt;/f:facet&gt;
              &lt;h:outputText value="#{file.language}          " /&gt;
          &lt;/rich:column&gt;
          &lt;rich:column style="width: 20px; " &gt;
              &lt;f:facet name="header"&gt;
                  &lt;h:outputLabel value="Is Default" /&gt;
              &lt;/f:facet&gt;
              &lt;h:outputText value="#{file.defaultness ? '++' : '--'}" /&gt;
          &lt;/rich:column&gt;
  
          &lt;rich:column&gt;
              &lt;f:facet name="header" style="width: 40px; " &gt;
                  &lt;h:outputLabel value="Details" /&gt;
              &lt;/f:facet&gt;
              &lt;a4j:commandLink action="#{uploadBean.deleteFile}" style="text-decoration:none; margin-left: 5pt;" value="Delete" 
                               reRender="attachmentUploadTableId" &gt;
                  &lt;f:setPropertyActionListener target="#{uploadBean.chosenFile}"
                                               value="#{file}" /&gt;
              &lt;/a4j:commandLink&gt;
              &lt;h:outputLabel/&gt;
              &lt;a4j:commandLink action="#{uploadBean.viewFile}" style="text-decoration:none; margin-left: 5pt;" value="Preview"&gt;
                  &lt;f:setPropertyActionListener target="#{uploadBean.chosenFile}"
                                               value="#{file}" /&gt;
              &lt;/a4j:commandLink&gt;
          &lt;/rich:column&gt;
      &lt;/rich:dataTable&gt;
  
  &lt;/h:form&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>and here is the java class corresponding:</p>
  
  <pre><code>public class UploadBean implements Serializable {
  
  private static final org.apache.log4j.Logger _logger = org.apache.log4j.Logger.getLogger(UploadBean.class);
  
  @Autowired PdfService pdfService;
  //private PdfService pdfService;
  
  private String filename;
  private String language;
  private Integer docId;
  private Boolean defaultness = Boolean.TRUE;
  // BLOB Handling
  // new ByteArrayInputStream(pdfFile.getPdf_data()), pdfFile.getPdf_data().length);
  private byte [] pdf_data;
  
  int i = 0;
  private List&lt;PdfFile&gt; fileList = new ArrayList&lt;PdfFile&gt;();
  private PdfFile chosenFile;
  
  private  List&lt;SelectItem&gt; languageOptions = initLanguageOptions();
  
  
  private List&lt;SelectItem&gt; initLanguageOptions(){
      List&lt;SelectItem&gt; list = new ArrayList&lt;SelectItem&gt;(3);
      list.add(new SelectItem("en", "English"));
      list.add(new SelectItem("de", "German"));
      list.add(new SelectItem("fr", "French"));
      list.add(new SelectItem("it", "Italian"));
      return list;
  }
  
  /**
   * get all files from the DB schema
   * @return
   */
      public List&lt;PdfFile&gt; getFileListByDocId() {
          Integer docId = getDocId();
          try {
              fileList = pdfService.getPDFFilesOnDocId(docId);
          } catch (Exception e) {
              _logger.error(e);
          }
  
          return fileList;
      }
      /**
       * get all files by DOC_ID from the DB schema
       * @param docId
       * @return
       */
      public List&lt;PdfFile&gt; getFileListByDocId(Integer docId) throws Exception {
          fileList.add( new  PdfFile().setLanguage("en").setFilename("first_File").setId(i++) );
      fileList.add( new PdfFile().setLanguage("de").setFilename("second_File").setId(i++) );
      fileList.add( new PdfFile().setLanguage("fr").setFilename("third_File").setId(i++) );
  
      //this.fileList = pdfService.getPDFFilesOnDocId(getDocId());
      return fileList;
  }
  
  // ActionEvent event EL version
  public String uploadAssignToOrder(){
      //event.getComponent().getAttributes();
      System.err.println("uploadAssignToOrder...");
      _logger.error("uploadAssignToOrder...");
  
      PdfFile file = new PdfFile();
      try {
          String fileName = JsfUtil.PDF_FILE_PREFIX + getDocId() + "_" + getLanguage();
          Integer defaultness = Boolean.TRUE.equals(getDefaultness()) ? 1 : 0;
  
          file.setFilename(fileName);
          file.setDocId(docId);
          file.setLanguage(language);
          file.setDefaultness(defaultness);
          file.setPdf_data(pdf_data);
  
          pdfService.insertFile(file);
          this.fileList = pdfService.getPDFFilesOnDocId(getDocId());
          //fileList.add(file);
          JsfUtil.addSuccessMessage("Pdf File attached for order Id:" + this.docId);
      } catch (Exception e) {
          e.printStackTrace();
          JsfUtil.addErrorMessage("Pdf File could not be attached for order Id:" + this.docId);
      }
      return null;
  }
  
  public void fileUploadListener(UploadEvent event) {
      InputStream is = null;
  
      try {
          JsfUtil.addSuccessMessage("uploadFile starting...");
          System.out.println("uploadFile(UploadEvent event)...for Doc Id:" + this.docId);
          _logger.info("In ActionListener of file upload for Doc Id:" + this.docId);
  
          UploadItem item = event.getUploadItem();
          _logger.info("item : " + item.getFileSize() + ", " + item.getContentType() + ", " + item.getData());
          if(item.getFile() != null) {
              _logger.info("File name and size : " + item.getFile().getPath() + ", " + item.getFile().getTotalSpace());
          }
  
          byte [] data = new byte[item.getFileSize()];
          is = new FileInputStream(item.getFile());
          is.read(data);
          is.close();
          // save the pdf_data of byte [] for the time being
          this.setPdf_data(data);
  
  //          PdfFile file = new PdfFile();
  //          file.setLanguage(getLanguage()).setPdf_data(data).setFilename(item.getFileName()).setDefaultness(1);
  //          pdfService.saveFile(file);
  //          fileList.add(file);
          System.out.println("uploadFile end...");
          _logger.info("uploadFile end...");
      } catch (Exception e) {
          e.printStackTrace();
          _logger.error(e.getMessage() + e);
      } finally {
          try {
              is.close();
          } catch (IOException IOE) {
              is = null;
          }
          is = null;
      }
  }
  
  public void setFileList(ArrayList&lt;PdfFile&gt; fileList) {
      this.fileList = fileList;
  }
  
  public List&lt;PdfFile&gt; getFileList() {
      //TODO  
      fileList.add( new PdfFile().setLanguage("en").setFilename("first_File").setId(i++) );
      fileList.add( new PdfFile().setLanguage("de").setFilename("second_File").setId(i++) );
      fileList.add( new PdfFile().setLanguage("fr").setFilename("third_File").setId(i++) );
  
      return this.fileList;
  }
  
  public String deleteFile() {
      try {
          getFileListByDocId().remove(chosenFile);
      } catch (Exception e) {
          e.printStackTrace();
      }
      return null;
  }
  
  public String viewFile() {
      return null;
  }
  
  
  
  public PdfFile getChosenFile() {
      return chosenFile;
  }
  
  public void setChosenFile(PdfFile chosenFile) {
      this.chosenFile = chosenFile;
  }
  
  public PdfService getPdfService() {
      return pdfService;
  }
  
  public void setPdfService(PdfService pdfService) {
      this.pdfService = pdfService;
  }
  
  public String getLanguage() {
      return this.language;
  }
  
  public void setLanguage(String language) {
      this.language = language;
  }
  
  public List&lt;SelectItem&gt; getLanguageOptions() {
      return languageOptions;
  }
  
  public Integer getDocId() {
      return this.docId;
  }
  
  public void setDocId(Integer docId) {
      this.docId = docId;
  }
  
  public String getFilename() {
      return this.filename;
  }
  
  public void setFilename(String filename) {
      this.filename = filename;
  }
  
  public byte[] getPdf_data() {
      return this.pdf_data;
  }
  
  public void setPdf_data(byte[] pdf_data) {
      this.pdf_data = pdf_data;
  }
  
  public Boolean getDefaultness() {
      return this.defaultness;
  }
  
  public void setDefaultness(Boolean defaultness) {
      this.defaultness = defaultness;
  }
  
  }
  </code></pre>
  
  <p>web.xml </p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;RichFaces Filter&lt;/filter-name&gt;
      &lt;filter-class&gt;org.ajax4jsf.Filter&lt;/filter-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;createTempFiles&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;maxRequestSize&lt;/param-name&gt;
          &lt;param-value&gt;50000000&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;RichFaces Filter&lt;/filter-name&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt;
      &lt;dispatcher&gt;FORWARD&lt;/dispatcher&gt;
      &lt;dispatcher&gt;INCLUDE&lt;/dispatcher&gt;
  &lt;/filter-mapping&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>