2 Replies Latest reply on Oct 22, 2010 7:35 AM by abhilashkollipara

    issue with rich:fileUpupload

    abhilashkollipara

      Hi,

       

      I need little help with rich:fileupload. My requirement is to upload an image and view the same after the upload is complete. Everything works fine if the bean is in session scope when i change the scope from session to request and upload the image, image is uploaded and if i print the byte array size it is displayed correct now paint method (method that displays the image that is uploaded, i use a4j:mediaoutput to display the uploaded image) is called to display the uploaded image and the i get a null pointer exception here

       

       

      SEVERE: Servlet.service() for servlet Faces Servlet threw exception
      javax.el.ELException: javax.faces.el.EvaluationException: org.apache.jasper.el.JspELException: /student/addStudent.jsp(79,4) '#{AddStudentBean.paint}' java.lang.NullPointerException

      SEVERE: Servlet.service() for servlet Faces Servlet threw exception

      javax.el.ELException: javax.faces.el.EvaluationException: org.apache.jasper.el.JspELException: '#{Bean.paint}' java.lang.NullPointerException

      Observation 1: If i print the byte array size in paint method i get null or if i initialize the byte array with some value then the same is printed.
      Observation 2: If the bean is in request scope the constructor is called again after the upload is complete and when the paint method is called.
      I used another bean that has a byte array and a blob and kept the same in session scope and used this bean in the class where i have upload and paint methods still i get the exception....
      Please help me understand what has to be done to achieve file upload in request scope.
      Thanks & Regards,
      Abhilash.
        • 1. Re: issue with rich:fileUpupload
          ilya_shaikovsky

          bean which holds uploaded image can't be request scoped. Because requests of upload and next one which shows the uploaded image - uses different instances in that case. and second request instance has no image in property already.

          • 2. Re: issue with rich:fileUpupload
            abhilashkollipara

            Thanks for your quick reply, i would to talk about 2 things here...

             

            1. I am using a4j:keepalive tag in the jsf page where i upload the image and display the same. The bean that is passed as an argument to the a4j:keepalive tag is the one which contains both the upload and paint methods.

             

            2. If cannot achieve this with the bean in request scope can you please suggest me with a solution to my problem. I cannot keep my bean in session as it holds too much of data. (My application allows a school to add a student any i have to take the complete details of the student including his / her medical data, parent details, guardian details and student details with respect to school - along with the student photo. My problem is i cannot put all this data in session).

             

            Thank you.