2

ACE コンポーネントを使用するためにライブラリ icefaces.jar icepush.jar icefaces_ace.jar をクラスパスに追加するとすぐに、名前を付けて保存ダイアログが表示されませんか? これがバグかどうかはわかりませんが、クラスパスにライブラリがなくても機能します。これが私の保存方法です:

    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(); 
        }
     }
4

1 に答える 1

2

ajaxを使用してファイルをダウンロードすることはできません。

Ajaxは、JavaScriptのXMLHttpRequestオブジェクトによって実行される内部にあります。要求は正常に実行され、応答は正常に取得されます。ただし、JavaScriptには、クライアントのディスクファイルシステムに応答を書き込む機能も、指定された応答で[名前を付けて保存]ダイアログを強制する機能もありません。それは大きなセキュリティ違反になります。

具体的な問題の原因はICEfaces自体です。つまり、ICEfacesをJSF Webアプリケーションに統合すると、すべての標準<h:commandXxx>リンク/ボタンがサイレントにajax対応のものに変わり、実際に初心者の間で混乱が生じます。ダウンロードリンク/ボタンがICEfacesで導入されたajax機能を暗黙的に使用していないことを確認してください。主題に関する彼らのウィキページに<f:ajax disabled="true">よると、これを無効にするには、明示的にネストする必要があります。

コンポーネントのAjaxを無効にする

個々のコンポーネントのレベルでAjaxを無効にすることもできます。

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

ダウンロードリンク/ボタンに適用します。

于 2012-11-16T18:36:13.857 に答える