JSF页面重新加载后,Flash数据丢失

时间:2016-04-21 10:57:23

标签: jsf flash-scope

我在页面中实现了JSF Flash:

第一页:

<h:commandLink value="#{item.number}" action="#{accounts.pageRedirect}">
    <f:setPropertyActionListener target="#{accounts.sessionValue}" value="#{item.number}" />
</h:commandLink>

public void setSessionValue(Object value) throws IOException
{
    Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
    flash.put("obj", value);
    flash.setKeepMessages(true);

}

public String pageRedirect()
{
    return "/accounts/AccountProfile.xhtml?faces-redirect=true";
}

第二页:

@PostConstruct
public void initData()
{
    id = (int) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("obj");
}

这两个页​​面都在javax.faces.view.ViewScoped

此解决方案有效,但我想在重新加载第二页时再次保留该值。现在,当我尝试领导第二页时,我获得了NPE。有什么解决方案吗?我可以使用Session范围,但这些应该是其他更简单的解决方案。

0 个答案:

没有答案
相关问题