Flash data is lost after JSF page reload

1.4k views Asked by At

I implemented JSF Flash in pages:

First page:

<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";
}

Second page:

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

Both pages are in javax.faces.view.ViewScoped

This solution works but I want when I reload the second page to keep again the value. Now I get NPE when I try to lead the second page. Is there any solution. I can use Session scope but these should be some other more simple solution.

0

There are 0 answers