1

我在页面中实现了 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 范围,但这些应该是其他一些更简单的解决方案。

4

0 回答 0