3

I have one view scoped JSF managed bean. In the action listener method of <p:commandButton> in this managed bean, I'm redirecting to another page as follows.

public void register() {
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    Flash flash = context.getFlash();
    flash.setKeepMessages(true);
    flash.put("emailId", emailId);
    context.redirect(((HttpServletRequest) context.getRequest()).getContextPath()+"/page.jsf");
}

page.jsf is bound to a request scoped bean in which I'm receiving the email address stored in a flash scope as follows.

<ui:define name="metaData">
    <f:metadata>
        <f:viewAction action="#{requestScopedBean.init}"/>
    </f:metadata>
</ui:define>
public void init() {
    String emailId = (String) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("emailId");
    System.out.println("emailId = "+emailId);
}

The email address is unavailable in the target bean. The email address in the target bean is required just to show the user who has registered to indicate that a message has been sent to that address so that the email address can be verified.

It produces the following warning on the server terminal.

WARNING: 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.

Why does this happen? My Mojarra version is 2.2.7

Tiny
  • 27,221
  • 105
  • 339
  • 599

0 Answers0