Flash Scope
In a web application is not hard to find a situation where it is needed to redirect a user using HttpServletResponse.sendRedirect method. When the sendRedirect method is used the data of the first request is lost. The image below explains how the redirect works:
It is not a good practice to use the User session (HttpSession) to store objects/information, attributes or values that would be lost after a redirect. Remember that to each user that uses the HttpSession it will be more memory of the server that will be allocated.
The JSF 2.0 has a very useful component named Flash Scope. This component will keep the object until the end of the redirect. It works like a Map<String, Object> that will keep the object temporarily in the session, and after the object is used its reference will be eliminated. The code below shows how to put an object inside the flash scope:
// class import
importcom.sun.faces.context.flash.ELFlash;
// use it before the redirect
ELFlash.getFlash().put("car", carObject);
To use the value in the page after the redirect just use it through the EL: “#{flash.car.color}“. Automatically the car reference will be removed from the container memory after the utilization of the car attribute.
Other good functionality of the Flash Scope is that it is possible to keep the object in the memory; to use this feature just access the object like this: “#{flash.keep.car.color}“. Just by adding the work keep before the object will indicate to the JSF it should not eliminate the object after using it (clique here to see more about it).



Really good material. Thanks very much…
Tugrul, thanks for the support! =D
Thank you very much !!!
You’re welcome [=
This Post is Awesome. Followed every things and applied on my project.
Hello surajtamang,
Thank you for your support.
very usefull material, Keep up the good work
Hello, John
Thanks for the support. [=
Really cool material! I agree with Tim. If this could be distributed in pdf format, you will become a little more famous. :) Thanks, good job!
Hello Thabita, good morning.
I will try to create the PDF, but I will not promise it! =D
Thanks for the support. [=
This is awesome! Could you post the entire article as a PDF for download??
Hello Tim.
I will try, I am really short of time. =/
Thanks for your support. [=