3 Replies Latest reply on Mar 8, 2010 10:09 AM by nbelaevski

    a4j:mediaoutput seems not to work properly with word documents

    agallo73

      Hello, I'm using the a4j:mediaoutput component and I decided to make my code enough generic to get some information as far as the file to be rendered (mime/type, element be it img or object and so on)  from a specific bean and pass the collected info to the mediaoutput.

       

      The mediaoutput is taken from the fileupload example with the changes described above.

       

      This is a brief piece of code describing what I did:

       

      <a4j:mediaOutput element="#{fileBean.element}" mimeType="#{fileBean.mimeType}"
                                          createContent="#{RendererBean.paint}" value="#{row}"
                                          width="450" height="500" cacheable="false" session="true">
                                            </a4j:mediaOutput>

       

      The paint method simply outputs the bynary data collected through the fileupload component to the stream. FileBean is the bean containing file related info for each uploaded file.

       

      All works well with images and pdf files but I have problems working with word documents. I'm unable to render .doc documents for instance.

       

      Is it a known limitation or there's some workaround? Is it necessary to have some plugin, define some classid or something else?

       

       

      Thanks in advance.

       

      Antonio.

        • 1. Re: a4j:mediaoutput seems not to work properly with word documents
          nbelaevski

          Hi,

           

          a4j:mediaOutput component does just two things:

           

          1) render HTML tag (OBJECT/IMG/APPLET/etc.) according to the defined component's attributes with the link to resource

          2) deliver resource contents to the client when browser requests it.

           

          Browser actually does the rest. So, for your case, you need to find out what settings (ClassID/Mime-Type) are required to embed Office documents. I suggest you to consult Office documentation/MSDN to find out some more information about this or wait for somebody from RF community to share experience. 

          • 2. Re: a4j:mediaoutput seems not to work properly with word documents
            agallo73

            Hello, I did not get any reply as far as this problem.

             

            I think that it should be an interesting concern providing a general component that works well with any document extension.

             

            I saw that using the type attribute instead of contentype something works better and pdf are properly rendered.

             

            I'd like to know which is the difference between type and contentype as far as the a4j:mediaoutput component is concerned.

             

            Problems still persist with office document such as excel, doc, docx and so on.

             

            I'm running my application on windows and I  saw that using the instruction

             

            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);

             

            the documents are properly rendered in an other page by the correct applications (word for doc documents, power point for ppt and so on).

             

            So my question is why does the mediaoutput not succeed in performing the same rendering ?

             

            Is there a way to invoke the process exec as described above and make the result appear in the mediaoutput?

             

            The rendering method of the mediaoutput component just takes data (that may be the file's bytes or the filename) and an output stream as inputs and I do not know how to use them in order to render the process and see the result.

             

             

            An other approach might be invoking the process and showing the result in a iframe or div element but I have no experience of this and I'd like to know which approach is better and would be greatful if someone smight suggest me some hint.

             

            Thanks.

             

            Antonio.

            • 3. Re: a4j:mediaoutput seems not to work properly with word documents
              nbelaevski

              Antonio,

               

              It's not possible to execute arbitrary process from the browser due to security reasons. Also possibility of embedding Office documents should be supported by your browser environment (i.e. I usually switch embedding PDF files off and you can't use anything to show them in browser then). Again only IE browser support ActiveX objects, others will need plugins. If documents embedding is supported by the environment, then you just have to set proper attributes for a4j:mediaOutput (CLSID or contentType) to get the document shown. If not, then you can convert documents to Flash format and use it, but again, if no Flash player installed, no way to show the document.