私はこの同様のSOの質問を読んでいますが、そこに提案されたアプローチのいくつかは私にはうまくいかないようです。私のスタックはJSF2.0(+ PrimeFaces)で、JBoss7ASにデプロイします。
(同じ戦争で) xhtmlページにリクエストをディスパッチするサーブレットがありますが、後者はそこに設定された属性の値を取得できません。
サーブレットコードスニペットは次のとおりです。
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
(...)
request.setAttribute("foo", "foo test");
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
そして、xhtmlページのコードは次のとおりです。
<p><h:outputText value="#{sessionScope['foo']}" /></p>
<p><h:outputText value="#{param['foo']}" /></p>
<p><h:outputText value="#{request.getParameter('foo')}" /></p>
3つのケースのいずれにも何も表示されません。
DIDの作業は、属性が次のように@PostConstructメソッドで取得されるバッキングBean(参照SOの記事への応答で提案されている)を使用することでした。
@PostConstruct
public void init() {
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance()
.getExternalContext().getRequest();
message = (String) request.getAttribute("foo");
}
...取得した値は、その後xhtmlページで利用できます。
しかし、なぜ一方の方法は機能するが、もう一方の方法は機能しないのでしょうか。