我使用 Flash 范围在 @viewscoped 控制器之间传递设置对象。但是,如果我在其中一个上重新加载页面,则闪存映射为空,并且设置对象未初始化。是否可以在页面重新加载时保持 Flash 范围?
我存储/检索设置的源代码:
拳头页.xhtml
...
<p:commandButton value="next"
action="#{firstPageController.transferConfig}"
process="@this" />
...
FirstPageController.java
@ManagedBean(name = "firstPageController")
@ViewScoped
public class FirstPageController {
...
public String transferConfig() {
FacesContext.getCurrentInstance().getExternalContext().getFlash().put("searchConfig", searchConfig);
return "/secondPage.xhtml?faces-redirect=true";
}
...
}
第二页.xhtml
...
<h:outputLabel value="value">
<f:event type="preRenderComponent" listener="#{secondPageController.onPageLoad()}"/>
</h:outputLabel>
...
SecondPageController.java
@ManagedBean(name = "secondPageController")
@ViewScoped
public class SecondPageController {
...
public void onPageLoad()
{
flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
searchConfig = ((SearchFilterConfig) flash.get("searchConfig"));
flash.putNow("searchConfig", searchConfig);
flash.keep("searchConfig");
}
...
}
我使用 Mojarra 2.1.29
谢谢