A JSF flash scoped example with pulling values from flash in the bean..

..triggered from the UI.

pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">
 
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>biz.tugay</groupId>
    <artifactId>jsftags</artifactId>
    <packaging>war</packaging>
 
    <version>1.0-SNAPSHOT</version>
 
    <name>jsftags</name>
    <url>http://maven.apache.org</url>
 
    <dependencies>
        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>javax.faces-api</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.13</version>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>el-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
 
    <build>
        <finalName>jsftags</finalName>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.1.v20140609</version>
                <configuration>
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                    <webApp>
                        <contextPath>/</contextPath>
                    </webApp>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                             http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
 
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
 
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
 
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
 
</web-app>

ReqScopedBackingBean.java
package biz.tugay.jsftags;
 
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.context.Flash;
 
/**
 * User: Koray Tugay (koray@tugay.biz)
 * Date: 6/24/2016
 * Time: 9:07 PM
 */
 
@ManagedBean
@RequestScoped
public class ReqScopedBackingBean {
    public void pullValuesFromFlash() {
        final Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
        final String firstname = (String) flash.get("firstname");
        final String lastname = (String) flash.get("lastname");
        setFirstname(firstname);
        setLastname(lastname);
        flash.keep("firstname");
        flash.keep("lastname");
    }
 
    private String firstname;
    private String lastname;
 
    public String getFirstname() {
        return firstname;
    }
 
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }
 
    public String getLastname() {
        return lastname;
    }
 
    public void setLastname(String lastname) {
        this.lastname = lastname;
    }
 
}

index.xhtml
<!DOCTYPE html>
<html xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
    <title>Index</title>
</h:head>
<h:body>
    <h:form>
        Firstname: <h:inputText value="#{flash.firstname}"/>
        <br/>
        Lastname: <h:inputText value="#{flash.lastname}"/>
        <br/>
        <h:commandButton action="hello?faces-redirect=true" value="Submit"/>
    </h:form>
</h:body>
</html>

hello.xhtml
<!DOCTYPE html>
<html xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
    <title>Hello</title>
</h:head>
<h:body>
    #{reqScopedBackingBean.pullValuesFromFlash()}
    Your firstname is: <h:outputText value="#{reqScopedBackingBean.firstname}"/>
    <br/>
    Your lastname is: <h:outputText value="#{reqScopedBackingBean.lastname}"/>
    <br/>
</h:body>
</html>

So what is so cool about this? So I am on index.xhtml, minding my own business:
and I hit Submit and I will see:
Your firstname is: Koray 
Your lastname is: Tugay 

but what is cool is, even when I refresh this page, I will still see these values!!! Great! All thanks to
flash.keep("firstname");
flash.keep("lastname");