JavaServer Faces ユーザーズガイド
目次 前ページ次ページ

第6章 Apcoordinatorの各機能の利用方法> 6.1 バイナリファイルの送受信

6.1.2 ファイルダウンロード

ファイルをダウンロードする場合は、managed beanにダウンロードを実行するアクションメソッド追加し、com.fujitsu.uji.faces.FacesMimeSupportクラスのfillResponseメソッドを実行します。


import java.io.File;
import com.fujitsu.uji.faces.FacesMimeSupport;
public class MyBean {
  .....
  public String download() {
    // ダウンロードするファイルを取得します
    File file = getDownloadFile();
    try {
      // ダウンロードを実行します
      FacesMimeSupport.fillResponse(file);
    } catch(Exception e) {
      e.printStackTrace();
    }
    return "ok";
  }
  .....
}
<f:view>
  <uji:form name="myform" >
    <uji:pushButton bean="myBean" property="button"
                  label="ダウンロード" action="#{mybean.download}"/>
  </uji:form>
</f:view>

目次 前ページ次ページ

All Rights Reserved, Copyright © 富士通株式会社 2006-2007