3 Replies Latest reply on Jun 8, 2010 2:40 AM by ilya_shaikovsky

    NullPointerException while UploadItem.getData() in <rich:fileUpload>

    elenaveretilo

      Hi all! I have one more problem(

      I want to use <rich:fileUpload> example from:

      http://livedemo.exadel.com/richfaces-demo/richfaces/fileUpload.jsf?tab=usage&cid=1447304

       

      But I get NullPointerException while UploadItem.getData() in FileUploadBean.java:

       

      public void listener(UploadEvent event) throws Exception{
       UploadItem item = event.getUploadItem();
       File file = new File();
       file.setLength(item.getData().length);
       file.setName(item.getFileName());
       file.setData(item.getData());
       files.add(file);
       uploadsAvailable--;
       }  
      

       

      item.getData() - throws NullPointerException.

       

      Here is my xhtml page:

       

      What could be wrong?

       

      Please - I need your help as soon as possible!

       

      Thanks and good luck!

        • 1. Re: NullPointerException while UploadItem.getData() in <rich:fileUpload>
          ilya_shaikovsky

          check CREATE_TEMP_FILES context param in developer reference guide.

          • 2. Re: NullPointerException while UploadItem.getData() in <rich:fileUpload>
            elenaveretilo

            Hi, thanks for quick reply!

            I didn't find anything about CREATE_TEMP_FILES context param, but I found out about init-param for RichFaces filter!

             

            I add <init-param> creataTempFiles to RichFaces filter definition and everything works fine)

             

                 <!-- Defining and mapping the RichFaces filter -->
                 <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>false</param-value>
                        </init-param>
                 </filter>
            

             

            Is that a correct solution? Or I need to work with CREATE_TEMP_FILES context param?

             

            And one more question - the button "Add" disabled if I add the number of files = uploadsAvailable (for my case it's only one file), and if I click "clear" - this button is still disabled. How can I set it enable, when I click "clear" link?

             

            Thanks!

            • 3. Re: NullPointerException while UploadItem.getData() in <rich:fileUpload>
              ilya_shaikovsky

              sorry my mistake in naming init-param as context-param Your way is correct now.