处理 ViewScoped ManagedBean 之间的数据

发布于 2024-11-10 10:18:08 字数 693 浏览 6 评论 0原文

我正在尝试这样做:

@ViewScoped
public class Bean2{
     public void saveChanges(){
         //saving changes...
         FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("id",id);
         FacesContext.getCurrentInstance().getExternalContext().redirect("page1");
     }
}

在 Bean1 中从 requestMap 获取数据,

@ViewScoped
public class Bean1{
    public Bean1(){
         String id =  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(id);
    }
}

但 id 始终为 NULL 并且 RequestMap 为空。 我尝试使用 getRequestParameterMap() 它也是空的...... 你知道如何在不改变bean范围并且不使用getSessionMap.put(parameters)的情况下解决这个问题吗? 谢谢

I am trying to do smth like this:

@ViewScoped
public class Bean2{
     public void saveChanges(){
         //saving changes...
         FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("id",id);
         FacesContext.getCurrentInstance().getExternalContext().redirect("page1");
     }
}

and in Bean1 to fetch data from requestMap

@ViewScoped
public class Bean1{
    public Bean1(){
         String id =  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(id);
    }
}

But id is allways NULL and RequestMap is empty.
I tried with getRequestParameterMap() it's also empty...
Do u know how to solve this problem without changing scope of beans and without using getSessionMap.put(parameters)...?
Thnx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

肩上的翅膀 2024-11-17 10:18:08

请求映射特定于 HTTP 请求。重定向指示浏览器发送请求。新的请求也意味着新的地图。

请求参数映射是请求参数的映射。因此您可以将其作为请求参数传递。

redirect("page1?id=" + id);

这样就可以通过新请求的请求参数映射来获取它。

The request map is specific to the HTTP request. A redirect instructs the browser to send a new request. A new request means also a new map.

The request parameter map is a mapping of, well, the request parameters. So you could pass it as a request parameter instead.

redirect("page1?id=" + id);

This way it's available by the request parameter map of the new request.

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