我使用flash scope在@viewscoped控制器之间传递一个设置对象.但是如果我在其中一个页面上重新加载页面,则flash地图为空,并且设置对象未初始化.是否可以在页面重新加载时保持闪存范围?
我的源代码存储/检索设置:
FistPage.xhtml
...
<p:commandButton value="next"
action="#{firstPageController.transferConfig}"
process="@this" />
...
Run Code Online (Sandbox Code Playgroud)
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";
}
...
}
Run Code Online (Sandbox Code Playgroud)
SecondPage.xhtml
...
<h:outputLabel value="value">
<f:event type="preRenderComponent" listener="#{secondPageController.onPageLoad()}"/>
</h:outputLabel>
...
Run Code Online (Sandbox Code Playgroud)
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");
}
...
}
Run Code Online (Sandbox Code Playgroud)
我使用Mojarra 2.1.29
谢谢