users@javaserverfaces.java.net

Problems with ui:repeat and flash scope

From: Björn Raupach <raupach.bjoern_at_googlemail.com>
Date: Mon, 15 Jul 2013 14:28:07 +0200

Hi group,

we have severall of these warning messages in our log file.

    com.sun.faces.context.flash.ELFlash.setCookie JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash. Any values stored to the flash will not be available on the next request.

We tracked it down due to a combination of ui:repeat and flash scope. In brief here is what we do.

<h:form>
  <ui:repeat var="item">
    <h:commandLink action="#{firstBean.new(var.store)}" value="New" />

Content is created in h:form with ui:repeat. We are (still) using commandLinks to navigate from page to page. We would like to retain some data. In this example it is the name of a store. So we put store in the flash and redirect to another page.

@ManagedBean
@ViewScoped
public class FirstBean {

    public String new(String store) {
        FacesUtils.getFlash().put("store", store);
        return "/secure/stores/new.jsf?faces-redirect=true";
    }

}

After I click one of those commandLinks the warning message is logged. The SecondBean binds to new.xhtml and read the store in its PostConstruct method.

@ManageBean
@ViewScoped
public class SecondBean {

    @PostConstruct
    public void initialize() {
        String store = (String) FacesUtils.getFlash().get("store");
    }

}

SecondBean can read the variable store from the flash. So the flash cookie was set, despite the warning saying otherwise. Interestingly the csfcfc cookie is still around. I checked with firebug.

My question: is this a bug, or shouldn't we using ui:repeat and flash scope together? We are using JSF 2.2.1.


greetings,
björn