読者です 読者をやめる 読者になる 読者になる

そごうソフトウェア研究所

SOA、開発プロセス、ITアーキテクチャなどについて書いています。Twitterやってます@rsogo

JSF FacesのMessageについてメモ

JSF FacesのMessageはFacesContextにキューイングされて、画面描写側のなんかで、取得することができます。
ところが、FacesContextの単位はリクエスト単位なので、リダイレクトなんかをやると、FacesContextのインスタンスが別のものになって、ロジック側でaddMessageしたメッセージが画面側でとれない。たぶん。

JSR-127, JavaServer Faces Specification Version: 1.1より抜粋

6.2 FacesMessage
Each message queued within a FacesContext is an instance of the
javax.faces.application.FacesMessage class. It offers the following
constructors:

2.1.3 Faces Request Generates Non-Faces Response
Normally, a JSF-based application will utilize the Render Response phase of the
request processing lifecycle to actually create the response that is sent back to the
client. In some circumstances, however, this behavior might not be desirable. For
example:

  • A Faces Request needs to be redirected to a different web application resource

(via a call to HttpServletResponse.sendRedirect).

Conversions and validations that failed will have caused messages to be enqueued
via calls to the addMessage() method of the FacesContext instance for the
current request, and the valid property on the corresponding component(s) will be
set to false.

6.1 FacesContext
...
A FacesContext
instance is created by the JSF implementation, prior to beginning the request
processing lifecycle, by a call to the getFacesContext method of
FacesContextFactory, as described in Section 6.5 “FacesContextFactory”.