开发者

JSF - Display MS word document on the web browser

For one of my projects, I need to display MS word document on web browser using JSF 2.0. The web application contains header, contents and so o开发者_运维知识库n. The MS word document should be displayed dynamically (using AJAX) on content part. The backing bean reads ms word document. I can display MS word document on browser using JSF as an independent application. But if call this from another JSF file this is not going to work. Could anybody throw some light on this issue ?

JSF independent application DiaplayDoc.xhtml. This will display MS document on the browser.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core">
    <f:event type="preRenderView" listener="#{DisplayDoc.downloadDoc}"/>    
</html> 

I need to call this page from another jsf file which contains other jsf components. The header portion will be executed, but not the footer part. (This works fine when the footer is set to display pdf plug ins or the images.)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      > 
<h:body>        
        <h:form id="form1">
           <div id="header">
               Hello World
            </div>
           <div id="footer">
            <object data="<Project>/DisplayDoc.jsf" type="application/msword" width="100%" height="100%">
            </object>
            </div>
        </h:form>
</h:body>
</html>

The bean part contains

response.reset();
response.setHeader("Content-Type", "application/msword");
response.setHeader("Content-Length", String.valueOf(fFile.length()));
response.setHeader("Content-Disposition", "inline; filename=\"" + strFilepath + "\"");


JSF is insuitable for this purpose. This way you malform the DOC output with a HTML doctype and other HTML tags around the binary DOC content. Replace it by a servlet and let the <object data> point to the servlet URL. If necessary, you can pass bean properties around as servlet request parameters like

<object data="docservlet?param1=#{bean.param1}&amp;param2=#{bean.param2}">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜