1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
FastWalker
  • 23
  • 5
  • did you take a look on this answer ?. http://stackoverflow.com/questions/9148798/object-in-flash-scope-is-not-available-after-redirect – Shady Hussein Apr 21 '16 at 11:05
  • You can use `#{flash.keep.obj}` in the page itself, but this is fishy. What exactly is the problem you're trying to solve? Are you well aware of http://stackoverflow.com/q/15521451? Ask yourself: how exactly should the page behave when enduser copypastes/bookmarks/shares URL and opens it in an entirely different session/application? – BalusC Apr 21 '16 at 11:07
  • @BalusC is this `flash.setKeepMessages(true);` same as `#{flash.keep.obj}`? – FastWalker Apr 21 '16 at 12:10
  • [Nope](http://docs.oracle.com/javaee/7/api/javax/faces/context/Flash.html). – BalusC Apr 21 '16 at 12:11
  • I tested it but the the result is the same. I get NPE here `id = (int) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("obj");` when I execute `` or page refresh. Any other proposals? – FastWalker Apr 21 '16 at 12:30

0 Answers0