p:fileDownload无法使用h:head

时间:2013-01-17 06:06:05

标签: jsf-2 primefaces download facelets head

我有<p:download>这样:

<h:form id="form1">
    <p:commandButton id="downloadLink" value="Download" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)"   
        icon="ui-icon-arrowthichk-s" actionListener="#{search.downloadActionListener}">   
        <p:fileDownload value="#{search.dwnloadFile}" />  
    </p:commandButton> 
</h:form>

它不起作用。下载按钮只是重新加载页面,而不显示另存为对话框。在检查了每一件事之后,我开始知道如果我从页面中删除<h:head>标签,那么它就会开始工作。

我无法在没有<h:head>的情况下工作,因为PrimeFaces看起来没什么感觉,并且所有ajax功能都依赖于它。


更新:生成的带有<head>的HTML <h:head>如下所示:

<head>
    <link href="/Project2.0/javax.faces.resource/themes/sam/theme.css.xhtml?ln=icefaces.ace" rel="stylesheet" type="text/css" />
    <link href="/Project2.0/rfRes/skinning.ecss.xhtml?db=eAG7mShzEgAFjAIg" rel="stylesheet" type="text/css" />
    <link href="/Project2.0/javax.faces.resource/primefaces.css.xhtml?ln=primefaces" rel="stylesheet" type="text/css" />
    <script src="/Project2.0/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces" type="text/javascript"></script>
    <script src="/Project2.0/javax.faces.resource/primefaces.js.xhtml?ln=primefaces" type="text/javascript"></script>
    <link href="/Project2.0/javax.faces.resource/dock/dock.css.xhtml?ln=primefaces" rel="stylesheet" type="text/css" />
    <script src="/Project2.0/javax.faces.resource/dock/dock.js.xhtml?ln=primefaces" type="text/javascript"></script>
    <link href="/Project2.0/javax.faces.resource/layout/layout.css.xhtml?ln=primefaces" rel="stylesheet" type="text/css" />
    <script src="/Project2.0/javax.faces.resource/layout/layout.js.xhtml?ln=primefaces" type="text/javascript"></script>
    <script src="/Project2.0/javax.faces.resource/jsf.js.xhtml?ln=javax.faces" type="text/javascript"></script>
    <script src="/Project2.0/javax.faces.resource/icepush.js.xhtml?v=9261182" type="text/javascript"></script>
    <script src="/Project2.0/javax.faces.resource/bridge.js.xhtml?v=9261182" type="text/javascript"></script>
    <script type="text/javascript">document.documentElement.isHeadUpdateSuccessful=true;</script>
    <style type="text/css">.ice-blockui-overlay {position: absolute;background-color: white;z-index: 28000;opacity: 0.22;filter: alpha(opacity = 22);}.ice-status-indicator-overlay {position: absolute;background-color: white;z-index: 28000;opacity: 0.22;filter: alpha(opacity = 22);}</style>
    <script src="/Project2.0/javax.faces.resource/compat.js.xhtml" type="text/javascript"></script>
    <script src="/Project2.0/javax.faces.resource/icefaces-compat.js.xhtml" type="text/javascript"></script>
    <title>
        Project
    </title>
    <link href="../Styles/Site.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/jquery-ui-1.8.6.custom.css" rel="stylesheet" type="text/css" />
</head>

并且没有<h:head>就像这样:

<head>
    <title>
        Project
    </title>
    <link href="../Styles/Site.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/jquery-ui-1.8.6.custom.css" rel="stylesheet" type="text/css" />
</head>

1 个答案:

答案 0 :(得分:1)

<h:head>的HTML输出表明您正在将PrimeFaces与ICEfaces混合。具体问题的主要原因是来自ICEfaces的这个脚本:

<script src="/Project2.0/javax.faces.resource/icefaces-compat.js.xhtml" type="text/javascript"></script>

This basically turns every non-ajax submit button into an ajax submit button。这还包括下载按钮。但是你不能用ajax下载文件。

完全删除ICEfaces。你不需要它。 It's basically a clone of PrimeFaces 2.x。但是如果你已经在使用PrimeFaces 3.x,那么ICEfaces完全没有额外的价值。也许这是以前试验过各种JSF组件库的遗留问题。

另见:


对于具体问题,

无关,HTML输出还表明您在运行时类路径中也有RichFaces。虽然理论上这应该与PrimeFaces一起使用,但我不建议将它们混合使用。 RichFaces本质上没有任何PrimeFaces没有提供的东西。