p:fileDownload不能使用h:head [英] p:fileDownload not working with h:head

查看:174
本文介绍了p:fileDownload不能使用h: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> 标签,那么它开始工作。

It doesn't work. The download button just reloads the page and doesn't show the Save As dialog. After checking every single thing, I came to know that if I remove the <h:head> tag from the page, then it starts to work.

我不能没有< h:head> 作为PrimeFaces看起来,所有的ajax功能取决于它。

I can't work without <h:head> as PrimeFaces look'n'feel and all ajax functionality depends on it.

更新:生成的HTML < head> < h:head> 是这样的:

Update: the generated HTML <head> with <h:head> is like this:

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


推荐答案

< h:head> 表示您正在将PrimeFaces与ICEfaces混合。您的具体问题的主要原因是ICEfaces的脚本:

The HTML output of the <h:head> suggests that you're mixing PrimeFaces with ICEfaces. The main cause of your concrete problem is this script from ICEfaces:

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

这基本上将每个非ajax提交按钮变成ajax提交按钮。这也包括下载按钮。但是您无法使用ajax下载文件。

This basically turns every non-ajax submit button into an ajax submit button. This also includes the download button. But you cannot download files with ajax.

完全删除ICEfaces。你不需要它它基本上是PrimeFaces 2.x的克隆。但是如果您已经使用PrimeFaces 3.x,那么ICEfaces完全没有额外的价值。也许这是从以前尝试使用各种JSF组件库的一个缺点。

Remove ICEfaces altogether. You don't need it. It's basically a clone of PrimeFaces 2.x. But if you're already using PrimeFaces 3.x, then ICEfaces has utterly no additional value. Perhaps it was a leftover from previous experimenting with various JSF component libraries.

  • ICEfaces libary in classpath prevents Save As dialog from popping up on file download

不相关的具体问题,HTML输出也表明您在运行时类路径中也有RichFaces。理论上应该与PrimeFaces一起工作,我不建议混合它们。 RichFaces本质上没有PrimeFaces尚未提供。

Unrelated to the concrete problem, the HTML output also suggests that you're also having RichFaces in the runtime classpath. Whilst that should theoretically work fine together with PrimeFaces, I wouldn't recommend mixing them. RichFaces has in essence nothing which PrimeFaces doesn't already offer.

这篇关于p:fileDownload不能使用h:head的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆