开发者

Handling Data between ViewScoped ManagedBeans

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜