I am passing a value from page 1 => page 2 using flash scoped variable.
After reaching the page 2 it is able to show the variable for first time.
When I reload the page the flash variable goes null.
Is there any way to retain the flash variable in page2 for the view scope?
Asked
Active
Viewed 542 times
0

Vishnudev K
- 2,874
- 3
- 27
- 42
-
Why do you want the value to persist? Flash scope is precisely defined for "survive one request". If you need messages to persist, you can probably iterate through the flash scope and stuff the ones you need into a `@ViewScoped` bean - I'm just wondering why you'd want to. – mabi Feb 25 '14 at 09:46
-
How can I set flash scoped values in page2's backing bean? – Vishnudev K Feb 25 '14 at 09:53
-
1You could keep the param for next redirection. Have a look at [this](http://stackoverflow.com/a/21277621/1199132) – Aritz Feb 25 '14 at 12:17
-
To keep the value in backing bean `@PostConstruct public void init() { myFlashVar= FacesContext.getCurrentInstance().getExternalContext().getFlash().get("flashkey"); }` – makata Feb 25 '14 at 12:21
-
@mek better put this as an answer, code in comments looks horrible. – mabi Feb 25 '14 at 12:24
1 Answers
1
But you can keep a flash scoped variable in backing bean of page 2 as
String myFlashVar;
@PostConstruct
public void init() {
myFlashVar= FacesContext.getCurrentInstance().getExternalContext().getFlash().get("flashkey"). toString();
}
Alternative way is
@ManagedProperty("#{flash}")
private Flash flash;//then you can access it as flash.get("flashkey")
You may also consider @ViewScoped.

makata
- 2,188
- 2
- 28
- 23
-
if i do a page reload those values are going off if its viewscoped, if bean is session scoped new values never been taken in the session – Vishnudev K Feb 28 '14 at 16:19
-
http://www.mkyong.com/jsf2/jsf-2-prerenderviewevent-example/ gave an example better than PostConstruct – Vishnudev K Feb 28 '14 at 16:36