ICEfaces的类路径prevents libary另存为对话框,在文件下载弹出 [英] ICEfaces libary in classpath prevents Save As dialog from popping up on file download

查看:216
本文介绍了ICEfaces的类路径prevents libary另存为对话框,在文件下载弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我添加了图书馆的icefaces.jar icepush.jar icefaces_ace.jar到我的类路径中才能使用ACE组件,我另存为对话框不会弹出?我不知道这是否是一个错误,但没有在类路径它的工作原理图书馆的。这是我作为保存方法:

 公共无效downloadFile(字符串的PropertyPath)抛出IOException异常{

     ProxyFile fileToDownload = repBean.downloadFile(的PropertyPath);

     FacesContext中的FacesContext = FacesContext.getCurrentInstance();
     的ExternalContext的ExternalContext = facesContext.getExternalContext();
     HttpServletResponse的响应=(HttpServletResponse的)externalContext.getResponse();

     response.reset(); response.setContentType(fileToDownload.getContentType());
     response.setHeader(内容长度,将String.valueOf(fileToDownload.getLength()));
     response.setHeader(内容处置,附件;文件名= \+ fileToDownload.getName()+\);

     的BufferedInputStream输入= NULL;
     的BufferedOutputStream输出= NULL;


     尝试 {
         输入=新的BufferedInputStream(fileToDownload.getContent());
         输出=新的BufferedOutputStream(response.getOutputStream());

         byte []的缓冲区=新的字节[10240]
         为(中间体长度;(长度= input.read(缓冲液))大于0){
            output.write(缓冲液,0,长度);
         }
     } 最后 {
         output.close();
         input.close();
         facesContext.responseComplete();
        }
     }
 

解决方案

您可以不使用AJAX下载文件。

阿贾克斯正在通过JavaScript的 XMLHtt prequest 对象执行的封面。该请求将被成功执行,响应将被成功取出。然而,JavaScript有没有工具来编写响应客户端的磁盘文件系统,也没有强制的另存为的给定的响应对话。这将是一个巨大的安全漏洞。

你的具体问题的原因是ICEfaces的本身。也就是说,当你在JSF Web应用程序集成的ICEfaces,所有标准< H:commandXxx> 链接/按钮,会悄悄地变成AJAX功能的人这的确引起的混淆起动器。确保下载链接/按钮不可用隐ICEfaces的引入AJAX设施。按照关于这个问题的他们 wiki页面,你需要明确地窝< F:。AJAX禁用=真正的> 来禁用此

  

禁用阿贾克斯组件

     

您还可以禁用阿贾克斯在单个组件的级别:

 < H:的commandButton值=发送的ActionListener =#{bean.sendMessage}>
    < F:AJAX禁用=真正的/>
< / H:的commandButton>
 

在你的下载链接/按钮,应用它。

As soon as I add the librarys icefaces.jar icepush.jar icefaces_ace.jar to my classpath in order to use ACE components, my SaveAs dialog won't popup? I'm not sure if this is a bug but without the librarys in classpath it works. Here's my save as method :

    public void downloadFile(String propertyPath) throws IOException {

     ProxyFile fileToDownload = repBean.downloadFile(propertyPath);

     FacesContext facesContext = FacesContext.getCurrentInstance();
     ExternalContext externalContext = facesContext.getExternalContext();
     HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();

     response.reset();         response.setContentType(fileToDownload.getContentType()); 
     response.setHeader("Content-Length", String.valueOf(fileToDownload.getLength()));
     response.setHeader("Content-disposition", "attachment; filename=\"" + fileToDownload.getName() + "\""); 

     BufferedInputStream input = null;
     BufferedOutputStream output = null;


     try {
         input = new BufferedInputStream(fileToDownload.getContent());
         output = new BufferedOutputStream(response.getOutputStream());

         byte[] buffer = new byte[10240];
         for (int length; (length = input.read(buffer)) > 0;) {
            output.write(buffer, 0, length);
         }
     } finally {
         output.close();
         input.close();
         facesContext.responseComplete(); 
        }
     }

解决方案

You can't download files using ajax.

Ajax is under the covers executed by JavaScript's XMLHttpRequest object. The request will be successfully executed and the response will be successfully retrieved. However, JavaScript has no facility to write the response to client's disk file system, nor to force a Save As dialogue with the given response. That would be a huge security breach.

The cause of your concrete problem is ICEfaces itself. Namely, when you integrate ICEfaces in a JSF web application, all standard <h:commandXxx> links/buttons will silently be turned into ajax-enabled ones which indeed causes confusion among starters. Make sure that the download link/button isn't implicitly using ICEfaces-introduced ajax facility. As per their wiki page on the subject, you need to explicitly nest a <f:ajax disabled="true"> to disable this.

Disable Ajax for a Component

You can also disable Ajax at the level of the individual component:

<h:commandButton value="Send" actionListener="#{bean.sendMessage}">
    <f:ajax disabled="true"/>
</h:commandButton>

Apply it on your download link/button.

这篇关于ICEfaces的类路径prevents libary另存为对话框,在文件下载弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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