【发布时间】:2010-08-09 13:52:59
【问题描述】:
在 ViewHandlerWrapper 实现中,我有以下代码:
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException {
final String token = UUID.randomUUID().toString();
HttpSession httpSession = (HttpSession) context.getExternalContext().getSession(true);
httpSession.setAttribute("expectedToken", token);
getWrapped().renderView(context, viewToRender);
}
如您所见,我想在 Session 中添加一个 UUID。在调试器之后,我可以看到该属性保留在 Session 上,直到 servlet 容器的整个请求-响应周期完成。但是,在下一次调用时,“expectedToken”属性为空。
在进入“老派”(获取 HttpSession)之前,我尝试在会话上操作一个值对象,这会呈现相同的结果。更改已取消。
这不应该起作用吗(毕竟调用renderView时没有提交响应)?
【问题讨论】: