JSFのアクションで独自の出力を行うには

JavaServer FacesCSV,PDFなどをダウンロードするためのアクションは、こんな風にするとよい。

@In private FacesContext facesContext;

public String someAction() {
    String encoding = "Windows-31J";
    String filename = getFilename(); // ファイル名を取得する。
    ExternalContext externalContext = facesContext.getExternalContext();
    HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
    response.setContentType("application/octet-stream; charset=" + encoding);
    response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
    response.setCharacterEncoding(encoding);
    PrintWriter writer = response.getWriter();
    writeCsvData(writer); // writerに出力する。
    facesContext.responseComplete();
    return null;
}

ポイントはFacesContext.responseComplete()で、これを呼んでおくとRenderResponseフェーズがスキップされる。

JBoss Seam と Spring

Seam 1.2の目玉は何といってもSpringとSeamのインテグレーションということになる。
Springで書きためてきたコードがそのままSeamに使えるとなれば、スムーズな移行が期待できる。
といっても、そううまくはいかないのが世の常ではあるけれど。

しばらくは、Gavin Kingの宣伝文句を信じて、ついて行ってみよう。
http://blog.hibernate.org/cgi-bin/blosxom.cgi/2007/02/27#thoughtsononedottwo

JBoss Seam 1.2.0.GA

1.1.7.GAになるはずが、1.2.0.GAに変更になったらしい?

DTDスキーマが軒並み1.2にバージョンアップされてます。

  • components-1.2.dtd
  • pages-1.2.dtd
  • spring-1.2.xsd
  • components-1.2.xsd
  • core-1.2.xsd
  • drools-1.2.xsd
  • framework-1.2.xsd
  • jms-1.2.xsd
  • mail-1.2.xsd
  • remoting-1.2.xsd
  • security-1.2.xsd
  • theme-1.2.xsd
  • web-1.2.xsd

Eclipse XML Schema キャッシュのクリア

JBoss SeamXMLファイルのDTDスキーマがバージョンが同じままで内容が変わるため、Eclipseのvalidationでエラーとなる場合がある。キャッシュをクリアすればいいのだがちょっとわかりにくいところにある。

  • Window->Preferences->Internet->Cacheの[Remove All]

JBoss WebアプリケーションのLogging

JBoss ASでは、Webアプリケーションでlog4j.xmllog4j.propertiesを設定しても無視されてしまう。
Webアプリケーションで独自のLogging設定を行うには、RepositorySelectorの仕組みを使用するとよい。
このとき、System.outおよびSytem.errがリダイレクトされているので注意すること。