Skip to main content

JSF Flash doesn't return data in the right order

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
devinderpal
Offline
Joined: 2011-02-14

I have a very simple implementation for this test.

LoginBackingBean has two methods which are called in 2 subsequent requests. Variable kept in flash memory during request 1 doesn't return in request 2 but in request 3.

To reproduce, "Simulate Login" button has to be clicked twice to retrieve from the flash. At first click, which is request 2, it returns null.

3 small files required to reproduce are attached. First referer.xhtml should be opened in a JSF app, then its login button calls doLogin method and takes you to Login.xhtml file. Now "Simulate Login" button need to be clicked twice to get the variable.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
devinderpal
Offline
Joined: 2011-02-14

couldn't find any way of attaching files, so here's the copy of important parts
Also, I have used @Named annotation in backing bean. you can also use @ManagedBean if you're not using an application server
--------------------------------login.xhtml----------------------------
<h:form>
<h1><h:outputLabel value="LOGIN PAGE"/> </h1>
<h:commandButton value="Simulate Login" action="#{login.goback}"></h:commandButton>
</h:form>
-------------------LoginBackingBean.java-----------------
@Named("login")
@RequestScoped
public class LoginBackingBean {

public String doLogin()
{
FacesContext.getCurrentInstance().getExternalContext().getFlash().put("mykey", "test2");
return "login.xhtml";
}

public String goback()
{
System.out.println("referer 2 is " +
FacesContext.getCurrentInstance().getExternalContext().getFlash().get("mykey"));
return "blahblah";
}
}
------------------------Referer.xhtml---------------------------------
<h:form>
<h1><h:outputLabel value="LOGIN PAGE"/> </h1>
<h:commandButton value="Simulate Login" action="#{login.goback}"></h:commandButton>
</h:form>