6 Replies Latest reply on Aug 6, 2009 11:06 AM by Ilya Shaikovsky

    call twice the paint bean on FF (when the page is loaded) an

    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).

      Code:

      <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);
       }


        • 1. Re: calls twice the paint bean on FF and 0 times on MSIE
          Patrick Coco Newbie

           

          "rigolissimo" wrote:
          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).



          This is similar to

          http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4038990#4038990

          There apaprently never was a clear answer to this problem.

          I can't believe there is no clear answer or working example for such an typical use (displaying PDF !) of Ajax and Richfaces...

          I would also appreciate an answer on this as I see this as critical for my project (I will not use a4j if this does not work on FF and MSIE).

          • 2. Re: call twice the paint bean on FF (when the page is loaded
            Patrick Coco Newbie

            Before I get told, this is "solved", let me say that I tried adding several ideas mentioned in

            http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4038990#4038990

            namely adding classid and mimeType.

            This does not help.

            See what

            <a4j:mediaOutput element="object" value="constante"
            uriAttribute="data" createContent="#{ReportBean.paint}"
            mimeType="application/pdf" id="pdf-preview" cacheable="false"
            classid="clsid:CA8A9780-280D-11CF-A24D-444553540000"
            session="true" width="300" height="300">
            </a4j:mediaOutput>

            generates (url shortened)



            Note : the classid is not generated
            the type (application/pdf) is not generated

            Adding directly the following attribute type="application/pdf" instead of mimeType="application/pdf" does not help (no type attribute gets generated on the object).

            And this does not display on MSIE 8 ...

            Could it be that this bug was closed too quickly
            https://jira.jboss.org/jira/browse/AJSF-34
            ?

            If not, could we get the syntax to get a PDF object display using <a4j:mediaOutput on MSIE 8 (and I suspect 6 and 7) ?

            [Also why does the paint method get called twice on FF?]

            • 3. Re: call twice the paint bean on FF (when the page is loaded
              Patrick Coco Newbie

              I wish we could edit posts... (the code generated was removed, it needed to be escaped)

              See what

              <a4j:mediaOutput element="object" value="constante"
              uriAttribute="data" createContent="#{ReportBean.paint}"
              mimeType="application/pdf" id="pdf-preview" cacheable="false"
              classid="clsid:CA8A9780-280D-11CF-A24D-444553540000"
              session="true" width="300" height="300">
              </a4j:mediaOutput>


              generates (url shortened)


              <object id="j_id2:pdf-preview" data="/richfaces-reporting/a4j/s/3_2_2.SR1org.ajax4jsf.reA__.jsf" height="300" width="300"></object>



              Note : the classid is not generated
              the type (application/pdf) is not generated

              Adding directly the following attribute type="application/pdf" instead of mimeType="application/pdf" does not help (no type attribute gets generated on the object).

              And this does not display on MSIE 8...

              Could it be that this bug was closed too quickly
              https://jira.jboss.org/jira/browse/AJSF-34?

              If not, could we get the syntax to get a PDF object displayed using <a4j:mediaOutput on MSIE 8 (and I suspect 6 and 7) ?


              • 4. Re: call twice the paint bean on FF (when the page is loaded
                Ilya Shaikovsky Master

                at first please be patien and not comment on all the thread you found. especially in deprecated forums.. We do not know in which thread you will wait for answer ;) And will not copy solution to all the threads.

                under investigation.

                • 5. Re: call twice the paint bean on FF (when the page is loaded
                  Patrick Coco Newbie

                   

                  "ilya_shaikovsky" wrote:
                  at first please be patien and not comment on all the thread you found. especially in deprecated forums.. We do not know in which thread you will wait for answer ;) And will not copy solution to all the threads.

                  under investigation.


                  Sorry, for the deprecated thread (disabling posting there would be nice).

                  I will check the answer here.

                  In the meantime, maybe this can help you, If I generate this code manually, it displays on MSIE 8 and FF (but the paint method is called twice on each, which seems a waste: producing a pdf dynamically is costly) :

                  <object id="j_id2:pdf-preview" data="http://localhost:8080/richfaces-reporting/a4j/s/3_2_2.SR1org.ajax4jsf.resource.UserResource/ncvA__.jsf" height="300" width="300" type="application/pdf" id="pdf-preview" >
                   <param name="src" value="http://localhost:8080/richfaces-reporting/a4j/s/3_2_2.SR1org.ajax4jsf.resource.UserResource/nvA__.jsf" />
                  </object>
                  


                  (url shortened)