1 Reply Latest reply on Aug 3, 2009 2:47 AM by Ilya Shaikovsky

    Why is the paint bean called twice on FF and never on MSIE 8

    Patrick Coco Newbie

      Why does the following code call twice the paint bean on FF (when the page is loaded) and never on MSIE 8 ???

      On FF, I see the paint object called twice (and the same PDF is always displayed).

      <rich:panel>
       <h:panelGrid id="previsu">
       <a4j:mediaOutput element="object" value="constante"
       uriAttribute="data" createContent="#{ReportBean.paint}"
       mimeType="application/pdf" id="pdf-preview" cacheable="false"
       session="true" width="300" height="300">
       </a4j:mediaOutput>
       </h:panelGrid>
       </rich:panel>
      
      Bean
      
      
       public void paint(OutputStream out, Object data) throws IOException
       {
       i++;
      
       File file= null;
      
       log.info(" Debug called " + i);
      
      // flip flop between two test files...
      
       if (i % 2 == 0)
       file = new File("c:/temp/File2.pdf");
       else
       file = new File("c:/tempFile1.pdf");
      
       FileInputStream in=null;
       byte[] bytes;
      
      
       try {
       in = new FileInputStream (file);
       long length = file.length();
      
       if (length > Integer.MAX_VALUE) {
       throw new IOException("The file is too big");
       }
      
       // Create the byte array to hold the data
       bytes = new byte[(int)length];
      
       // Read in the bytes
       int offset = 0;
       int numRead = 0;
       while (offset < bytes.length
       && (numRead=in.read(bytes, offset, bytes.length-offset)) >= 0) {
       offset += numRead;
       }
      
       // Ensure all the bytes have been read in
       if (offset < bytes.length) {
       throw new IOException("The file was not completely read: " + file.getName());
       }
      
       } finally {
       if (in != null) {
       in.close();
       }
       }
      
       log.info("Paint " + bytes.length + "bytes");
       out.write(bytes);
       }