开发者

Handling Data between ViewScoped ManagedBeans

开发者 https://www.devze.com 2023-03-09 17:32 出处:网络
I am trying to do smth like this: @ViewScoped public class Bean2{ public void saveChanges(){ //saving changes...

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().getExternalC开发者_开发知识库ontext().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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号