通过 FacesContext 传递请求参数
我从 JSF 1.2 迁移到 JSF 2.0,似乎在切换过程中我错过了一些东西。我有以下场景:
- 一页上有一个按钮,actionListener 设置为一个托管 bean 的方法,该方法通过调用 FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("foo" 添加一个对象来请求, fooObject);
- 导航已正确处理到初始化了其他托管 bean 的其他页面。
- 其他托管 Bean 的构造函数尝试通过调用 FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("foo"); 来检索请求中传递的对象,并使用接收到的值初始化自身。
两个托管 bean 都是请求范围的。我注意到构造函数无法从请求中检索正确的值,因为请求映射不包含“foo”键。
我做错了什么?有更好的方法吗?
提前致谢。
I moved from JSF 1.2 to JSF 2.0 and it seems I missed something during the switch. I have following scenario:
- There is a button on one page with actionListener set to one managed bean's method which adds an object to request by calling
FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("foo", fooObject);
- Navigation is properly handled to other page where other managed bean is initialized.
- The constructor of other managed bean tries to retrieve passed object from request by calling
FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("foo");
and to initialize itself with received values.
Both managed beans are request scoped. I notice that constructor can't retrieve proper value from request because request map doesn't contain "foo" key.
What am I doing wrong? Is there a better way to do this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在步骤 2 中,如果存在重定向,则初始请求范围将丢失,因为重定向将导致另一个请求。
In step 2, if there is a redirect the initial request scope is lost as the redirect would result in another request.