处理 ViewScoped ManagedBean 之间的数据
我正在尝试这样做:
@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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请求映射特定于 HTTP 请求。重定向指示浏览器发送新请求。新的请求也意味着新的地图。
请求参数映射是请求参数的映射。因此您可以将其作为请求参数传递。
这样就可以通过新请求的请求参数映射来获取它。
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.
This way it's available by the request parameter map of the new request.