通过 FacesContext 传递请求参数

发布于 2024-09-29 02:53:09 字数 509 浏览 2 评论 0原文

我从 JSF 1.2 迁移到 JSF 2.0,似乎在切换过程中我错过了一些东西。我有以下场景:

  1. 一页上有一个按钮,actionListener 设置为一个托管 bean 的方法,该方法通过调用 FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("foo" 添加一个对象来请求, fooObject);
  2. 导航已正确处理到初始化了其他托管 bean 的其他页面。
  3. 其他托管 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:

  1. 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);
  2. Navigation is properly handled to other page where other managed bean is initialized.
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱桃奶球 2024-10-06 02:53:09

在步骤 2 中,如果存在重定向,则初始请求范围将丢失,因为重定向将导致另一个请求。

In step 2, if there is a redirect the initial request scope is lost as the redirect would result in another request.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文