【问题标题】:send object from @ViewScoped controller to other @ViewScoped controller after clicking on <h:commandButton> in CDI Bean JSF2.0 [duplicate]单击CDI Bean JSF2.0中的<h:commandButton>后,将对象从@ViewScoped控制器发送到其他@ViewScoped控制器[重复]
【发布时间】:2018-04-17 15:20:48
【问题描述】:

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

提前谢谢你

【问题讨论】:

标签: jsf cdi managed-bean


【解决方案1】:

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

//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 ");

【讨论】:

  • 不工作:(。对象在另一个 Bean 中仍然为空。我试图在 @PostConstructor 中显示它是空的
  • 对象为空有效,尝试使用自己的对象代替对象。
  • 我刚刚更新了代码,再试一次就可以了。
猜你喜欢
  • 2015-04-15
  • 1970-01-01
  • 1970-01-01
  • 2016-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多