5 Replies Latest reply on Mar 27, 2009 7:06 AM by Ilya Shaikovsky

    Dynamic file upload data turn to null

    panky_p Novice

      Hi,
      I am trying to create a dynamic rich file upload, I have added the file upload listener, It shows the uploaded file but when I try to save the uploaded data some times it turns to null, and some time I am able to save the data properly.

      Why is it so?
      Any one has idea???

        • 1. Re: Dynamic file upload data turn to null
          Ilya Shaikovsky Master

          provide more information like page and bean code used, environment info, web.xml and steps performed on the page.

          • 2. Re: Dynamic file upload data turn to null
            panky_p Novice

            Hi Ilya,
            I am using Seam 2.1.0.SP1 and RF 3.2.2.SR1

            my upload listener is in EditBean

            public void fileUploadListener(UploadEvent event) throws IOException
             {
             UploadItem uploadItem = event.getUploadItem();
             HtmlFileUpload htmlFileUpload = (HtmlFileUpload)event.getSource();
             if (uploadItem.isTempFile()){
             try{
             FileUploadBean fileUploadBean = new FileUploadBean();
             File file = uploadItem.getFile();
             FileInputStream fs = new FileInputStream(file);
             int numberBytes = fs.available();
             byte bytearray[] = new byte[numberBytes];
             fs.read(bytearray);
             fileUploadBean.setData(bytearray);
             fileUploadBean.setFileName(uploadItem.getFileName());
             fileUploadBean.setContentType(uploadItem.getContentType());
             htmlFileUpload.setUploadData(fileUploadBean);
             fis.close();
            
             }catch(FileNotFoundException fnf){
            
             }catch(IOException ioe){
            
             }catch(Exception ex){
            
             }
             }
             }

            and my component bean contains following code for file upload
            HtmlFileUpload newFileUpload = new HtmlFileUpload();
            String fileUploadId = "upload_file";
            newFileUpload.setId(fileUploadId);
            newFileUpload.setAddControlLabel("Select");
            newFileUpload.setListWidth("300");
            newFileUpload.setListHeight("300");
            newFileUpload.setMaxFilesQuantity(1);
            newFileUpload.setImmediateUpload(true);
            newFileUpload.setAjaxSingle(true);
            
            MethodBinding fileUploadListener = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{editBean.fileUploadListener}", new Class[] {UploadEvent.class});
            newFileUpload.setFileUploadListener(uploadListener);

            and in web.xml i had
             <context-param>
             <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
             <param-value>server</param-value>
             </context-param>
            <filter>
            <filter-name>Seam Filter</filter-name>
            <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
            <init-param>
             <param-name>createTempFiles</param-name>
             <param-value>false</param-value>
             </init-param>
            </filter>
            



            Please tell me where i am wrong!!

            • 3. Re: Dynamic file upload data turn to null
              Ilya Shaikovsky Master

              so you defined

              <init-param>
               <param-name>createTempFiles</param-name>
               <param-value>false</param-value>
               </init-param>
              


              and trying to use file
              if (uploadItem.isTempFile()){
              
              ..
              
              File file = uploadItem.getFile();
              


              it's wrong.

              • 4. Re: Dynamic file upload data turn to null
                panky_p Novice

                Thanks for quick reply!!
                I did changes to

                <init-param>
                 <param-name>createTempFiles</param-name>
                 <param-value>true</param-value>
                 </init-param>

                but still I am getting the same behavior.


                • 5. Re: Dynamic file upload data turn to null
                  Ilya Shaikovsky Master

                  so could you just debug your listener and check where the problem is. We have normal saving using both methods as you could see from our samples.