- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有多个页面允许下载相同的资源(从我的数据库中检索)。
问题是下载只适用于其中的一些,即使使用相同的代码并调用相同的 bean。
这件事变得很烦人,因为在非工作页面上,单击下载链接只会重新加载页面而不会出现任何消息/异常,所以我不知道发生了什么。
这是我的 BEAN 代码:
package ManagedBeans;
import ejb.DispensaManagerLocal;
import entity.Dispensa;
import entity.Utente;
import java.io.ByteArrayInputStream;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.RateEvent;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
/**
*
* @author stefano
*/
@ManagedBean
@RequestScoped
public class DispensaBean {
@EJB
private DispensaManagerLocal dispensaManager;
@ManagedProperty(value = "#{loginBean.utente}")
private Utente utente;
public Utente getUtente() {
return utente;
}
public void setUtente(Utente utente) {
this.utente = utente;
}
/**
* Creates a new instance of DispensaBean
*/
public DispensaBean() {
}
public StreamedContent getDownload() {
String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("dispensaId");
System.out.println("________" + id);
Dispensa d = dispensaManager.findById(Integer.parseInt(id));
String type = getMimeFromByte(d.getDatiFile());
String estensione = "";
if(type.equals("application/pdf")){
estensione = ".pdf";
} else if(type.equals("application/zip")) {
estensione = ".zip";
} else if(type.equals("application/vnd.ms-powerpoint")) {
estensione = ".ppt";
}
return new DefaultStreamedContent(new ByteArrayInputStream(d.getDatiFile()), type, d.getTitolo() + estensione);
}
private String getMimeFromByte(byte[] src) {
if (src[0] == 0x25 && src[1] == 0x50 && src[2] == 0x44 && src[3] == 0x46) {
return "application/pdf";
}
if (src[0] == 0x50 && src[1] == 0x4b) {
return "application/zip";
}
if (src[0] == 0xd0 && src[1] == 0xcf && src[2] == 0x11 && src[3] == 0xe0 && src[4] == 0xa1 && src[5] == 0xb1 && src[6] == 0x1a && src[7] == 0xe1) {
return "application/vnd.ms-powerpoint";
}
return "application/octet-stream";
}
}
现在,在非工作页面上,不会调用 getDownload()
方法,因为它不会打印任何内容。
这是下载按钮代码
<h:form style="float: right">
<pou:commandLink id="downloadDispensa" ajax="false" disabled="#{!loginBean.logged}">
<pou:graphicImage value="./resources/images/download.png" height="30"/>
<pou:fileDownload value="#{dispensaBean.getDownload()}"/>
<f:param name="dispensaId" value="#{dispensa.id}"/>
</pou:commandLink>
</h:form>
我注意到下载链接只是重新加载页面而不是调用方法,这只发生在 #{dispensa.id}
依赖于 GET 参数的页面中.
例如,我有一个名为 dispensa.xhtml
的页面,如果没有传递 GET 参数,它会显示我在数据库中的所有文件。
事实上,dispensa.xhtml?id=5
将只显示 id=5 的文件。
在第一种情况下,单击下载链接没有问题。在第二种情况下这样做会重新加载页面并丢失 GET 参数,因此它将加载 dispensa.xhtml
而不是 dispensa.xhtml?id=5
。
我认为使用 GET 参数存在一些问题,但是..昨天它起作用了,我没有更改这段代码!
另一个非工作页面是 ricerca.xhtml
,它显示了 ricerca.xhtml?key=query
给出的查询的(多个)结果。
最后,搞砸了,profile.xhtml?user=username
中的下载工作。
这破坏了我关于 GET 参数的整个理论。
为了避免出现空的 byte[] datiFile
,我以这种方式编辑了我的 Dispensa
实体:
@Basic(optional = true, fetch=FetchType.EAGER)
@Lob
@Column(name = "datiFile")
private byte[] datiFile;
我不知道该怎么办,因为它没有说明出了什么问题,它只是重新加载页面,绕过了我的下载!
编辑:
我已经尝试更改我的 getDownload()
方法以返回我 HD 上的 File
,以了解问题是否是由硬盘上的空数据引起的db 但它仍然没有像我说的那样工作!
最佳答案
似乎我使用替代解决方案解决了这个问题。
我都改了
<h:form style="float: right">
<pou:commandLink id="downloadDispensa" ajax="false" disabled="#{!loginBean.logged}">
<pou:graphicImage value="./resources/images/download.png" height="30"/>
<pou:fileDownload value="#{dispensaBean.getDownload()}"/>
<f:param name="dispensaId" value="#{dispensa.id}"/>
</pou:commandLink>
</h:form>
到
<h:form style="float: right">
<h:outputLink id="downloadDispensa" disabled="#{!loginBean.logged}" target="_blank" value="./download.xhtml?id=#{dispensa.id}">
<pou:graphicImage value="./resources/images/download.png" height="30"/>
</h:outputLink>
</h:form>
download.xhtml
有这段代码:
<script type="text/javascript">
if(document.referrer == "" || document.referrer == "download.xhtml"){
self.location='./index.xhtml';
}
document.onblur = new Function('self.close()');
</script>
<h:body onload="document.getElementsByClassName('downloadDispensa')[0].click();" rendered="#{loginBean.logged}">
<h:form>
<h:commandLink class="downloadDispensa" id="downloadDispensa" style="display: none">
<pou:graphicImage value="./resources/images/download.png" height="30"/>
<pou:fileDownload value="#{dispensaBean.download}"/>
<f:param name="dispensaId" value="#{request.getParameter('id')}"/>
</h:commandLink>
</h:form>
</h:body>
<h:body onload="self.location='./index.xhtml';" rendered="#{!loginBean.logged}">
</h:body>
因此它加载下载页面,自动点击下载链接,并在显示下载对话框时自动关闭页面。
关于jsf - 未调用 PrimeFaces fileDownload 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10563108/
我想为每个条显示不同颜色的 primefaces 条形图。我得到的最接近的就像图像: 我想用不同的颜色来表示这些条,比如绿色代表“准时”,黄色代表“警告”,红色代表“逾期” 我尝试使用 model.s
我对 Primefaces 3 对话框的构造感到困惑。 我在 SO 中看到了具有这种模式的问题。表单在对话框之外。 但另一个问题有这个。 Primef
我尝试使用一个简单的gmap示例开始开发Web应用程序,但是它对我不起作用。 我使用了在网页上找到的示例电影收藏家。我只在template.html文件中包含了这个代码。 我收到此错误: javax.
我正在使用 primefaces 3.0。我有三个文本字段,其中任何一个都是必需的。我如何在 primefaces 中验证这一点。请帮忙..谢谢 最佳答案 通常,当在组件上使用自定义 f:valida
我正在尝试为 primefaces 选择列表创建自定义过滤器。当我按照手册中的说明进行操作时,我在 primefaces 的某处遇到了 TypeError。 我对picklist的定义 我的过滤
我正在努力处理primefaces日历。我需要的是,如果今天是 2011 年 7 月 28 日,我可以限制用户选择 7 月 28 日之前 1 年和 7 月 28 日之后 3 年的日期。 我查看了 pr
有没有办法删除 p:datatable 标题上的全选复选框。 我需要单个行上的复选框,而不是标题上的复选框。 最佳答案 这非常有效: .ui-chkbox.ui-chkbox-all.ui-widge
Primefaces 3.5,Mojarra 2.1.14。这是我的 PF 数据表,它包含一个名为“自动”的不可编辑 bool 列和可编辑的“标签”列:
我想在向导的最后一个选项卡上隐藏后退按钮。 我正在使用素面。它的解决方案是什么? 谢谢 最佳答案 您可以使用 jQuery 在客户端执行此操作: 假设您正在使用展示中的向导:http://www.pr
如果我在 PrimeFaces 数据表中设置属性“scrollable=true”,它可以垂直滚动。但是可以水平滚动这个表格吗? 最佳答案 Primefaces 支持在数据表上水平滚动。只需像这样指定
我有这个代码。在用户选择一行并关闭对话框之后,它将触发rowSelect事件。在我更新为primfaces 3.3(我安装了ver3.2)之前,它工作得很好。我在控制台中没有任何异常,当我调试时,我看
是否存在任何方法来设置 primefaces 的日历组件的年份列表? 最佳答案 对于年份列表,您可以使用 navigator="true" p:calendar 中素面的属性标记和年份范围 c-100
我正在使用 primefaces 3.2。我已经准备好了向导,可以在数据表的同一页面上插入用户信息。向导逐个选项卡获取信息并在确认选项卡上提交。它还将反射(reflect)在数据表的同一页面上。它运行
我有一个 p:treeTable,树内容都在一列中。该树是一个共享组件,因此我的某些页面需要列标题,而有些则不需要。在列标题为空的页面中,它为列标题创建一个空行,这是我不想要的。我确实想要列内容,只是
我使用的是primefaces 3.4,我在 p:overlaypanel 中有一个 p:calendar 。当我选择日期时,覆盖面板关闭(使用 Google Chrome 时)当我使用 Firefo
当我使用日历时,我将“timeOnly”设置为“true”,将“pattern”设置为“HH:mm a”。 当输入时间大于或等于“13:00 pm”时,日历每次获得焦点,都会 自动将时间更改为“23:
我也在尝试获取枚举“CityCodes.java”中定义的城市代码,这是我的枚举类,我的定义如下: public enum Cities { AL("Alabama","1"), AK("Alaska
在 PrimeFaces 展示页面上有一个简单的标题栏,适合实际主题。我的意思是此页面上的“欢迎来到 PrimeFaces 展示”文本:http://www.primefaces.org/showca
是否可以在 Primefaces 中创建垂直菜单栏? 我习惯了像 Ext-JS 这样简单的纯 AJax 框架,但到目前为止我还没有在 PF 中看到这样的组件。 谢谢, 乔 最佳答案 它被称为分层菜单。
是否可以设置 Primefaces 的 ScrollPanel 的滚动速度? Scrollpanel 在“ native ”模式下的滚动速度可以,但在“默认”模式下不行。 我使用的是 Primefac
我是一名优秀的程序员,十分优秀!