JSF 2.2 Flash Scope Example
JSF 2.2 Flash Scope Example
In this article I will try to explain you how to use the flash scope in Java EE.
Introduced in JSF 2.0, the flash scope provides a short-lived conversation (flash session). It is a way to pass temporary objects (not only strings) that are propagated across a single view transition and cleaned up before moving on to another view. The flash scope can only be used programmatically as there is no annotation.
In some cases we need to redirect from one view to another view in JSF. But when we do a redirect we lost everything that is stored in the url with a GET request. One solution is to use an EL expression of the abstract class Flash #{flash.foo}. So, this is a pretty simple solution to redirect without lost anything:
Source files:
index.xhtml

The special thing here is the use of #{flash.foo}, where foo is the name of the variable in the flash scope.
ExampleController.java

The goal of this controller is just to do a redirect from the index.xhtml to the target.xhtml.
target.xhtml

Here we fetch the value of the foo variable by doing again #{flash.foo} to display the data.
The results:

This is the first page with the message Hello World.
And finally this is the second page (target.xhtml) wich displays the message from the previous page.
Final Considerations
We’ve learned how to pass values with the help of flash from one view to another with redirects.
Notice that if you refresh the second page after it shows up, all the data has gone. That’s because the flash scope was destroyed immediately when the rendering of the second page occurs. This is the goal of the flash scope. It just holds some values (in a flash session) between one HTTP request and the subsequent HTTP response.
This type of scope must be done programmatically. There is no annotation, like there is, for example, to the request scope (@RequestScoped).
10 Programming Languages You Should Learn in 2014
from Pocket http://ift.tt/1ehEAFf
The tech sector is booming. If you’ve used a smartphone or logged on to a computer at least once in the last few years, you’ve probably noticed this. As a result, coding skills are in high demand, with programming jobs paying significantly more than the average position.
JavaScript for Java developers
from Pocket http://ift.tt/1lKH6HM
Although JavaScript and Java sound and look similar they are very different in their details and philosophies. Here I try to compare the two languages regardless of their libraries and frameworks.
JSF 2.2: HTML 5 Support
from Pocket http://ift.tt/1n0Xtjt
HTML 5 is the fifth version of the HTML markup Standard. HTML5 arose as a result of ideas and needs such as developing new generation web applications, providing standardization between browsers and using a single codebase. Back end and UI developers can benefit from a single codebase with HTML5.
Under construction
Welcome
Welcome to my web site!
Here you can navigate through my portfolio, some tutorials and other stuff.
I hope you enjoy it…
1 2 3 |
public static void main(String[] args){ System.out.println("Welcome!!"); } |