在CDI Bean JSF2.0中单击<h:commandbutton>后,将对象从@ViewScoped控制器发送到其他@ViewScoped控制器

时间:2018-04-17 15:20:49

标签: jsf cdi managed-bean

我想从控制器获取一个对象,该对象位于具有相同范围的其他控制器的@ViewScoped范围内。我怎么能实现这一点,因为我知道我不是在重定向情况下我想在点击一个动作按钮后得到它。

提前谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用faces上下文的会话映射,如下所示:

//In view Scope 1 pass the object 
String strObj = "Use your object here";
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.getSessionMap().put("obj", strObj );

//In view scope 2 get the object
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
String strObj = (String)ec.getSessionMap().get("strObj ");
相关问题