Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8871801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:04:52+00:00 2026-06-14T18:04:52+00:00

I have a problem with JSF’s FlashScope, note that I’m aware that the redirect

  • 0

I have a problem with JSF’s FlashScope, note that I’m aware that the redirect should point to the same base path as the calling page.

My case, the action will be initialized when a client click a link from his/her email, then it will load a .xhtml (has a preRenderView event) page with a backing bean to check the parameters passed. When the parameters are wrong it must redirect to a new page with message.

The View:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

    <f:metadata>
        <f:viewParam name="dummy" />
        <f:event listener="#{signupMaterialBean.initFromContext()}"
            type="preRenderView"></f:event>
    </f:metadata>

    <h:outputText value="#{signupMaterialBean.html}" escape="false"></h:outputText>

</ui:composition>

The Backing Bean:

public void initFromContext() {
    try {
        Map<String, String> params = facesContext.getExternalContext()
                .getRequestParameterMap();
        ...
    } catch (NullPointerException e) {      
        try {
            Message message = new Message();
            String msg = "Invalid parameters";
            message.setMessage(msg);

            JSFUtils.flashScope().put("message", message);

            facesContext.getExternalContext().redirect("message.xhtml");
            facesContext.responseComplete();
        } catch (IOException ioe) {
        }
    } catch (IOException e) {
    }
}

The redirect works, but the message save in FlashScope is gone. Any idea why the flash scope is being deleted or another way to do it?

message.xhtml

    <ui:define name="head"></ui:define>

    <ui:define name="content">
        <div class="box-middle-content faded">
            <div class="message">
                <h:outputText escape="false" value="#{flash.message.message}"></h:outputText>
                <br />
                <p>
                    <h:outputText value="#{msgs['message.footer']}" escape="false" />
                </p>
            </div>
        </div>
    </ui:define>
</ui:composition>

JSFUtils

public class JSFUtils {
    public static Flash flashScope() {
        return (FacesContext.getCurrentInstance().getExternalContext()
                .getFlash());
    }
}

Updated view:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    xmlns:of="http://omnifaces.org/functions">

    <f:metadata>
        <f:viewParam name="dummy"></f:viewParam>
        <f:event type="postInvokeAction"
            listener="#{signupMaterialBean.initFromContext}" />
    </f:metadata>

    <h:outputText value="#{signupMaterialBean.html}" escape="false"></h:outputText>

</ui:composition>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:04:53+00:00Added an answer on June 14, 2026 at 6:04 pm

    The <f:event type="preRenderView"> is too late to set a flash scoped attribute. The flash scope can’t be created when JSF is currently sitting in render response phase. You basically need to set the flash scoped attribute before render response phase. In spite of the name preRenderView, this event is actually fired during (the very beginning of) the render response phase.

    You’d basically need to invoke the listener method during INVOKE_ACTION phase. As there’s no standard <f:event> type for this, you’d need to homegrow one. This is outlined in detail in this answer: Can't keep faces message after navigation from preRender.

    You’d ultimately like to end up as:

    <f:event listener="#{signupMaterialBean.initFromContext()}"
             type="postInvokeAction" />
    

    Note that this event is already provided by OmniFaces. See also the InvokeActionEventListener showcase page which handles exactly this issue.


    Unrelated to the concrete problem, the catch on NullPointerException is a huge code smell. Don’t catch runtime exceptions like that. Prevent them by performing nullchecking as if (foo != null) and so on. Also those empty catches on IOException are very bad. Remove them all and just add throws IOException to the method.

    Further, the redirect path problem is fixed since Mojarra 2.1.14. So since that version you could safely redirect to a different base path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m creating an app using JSF. The problem I have is that every
I have a problem with the JSF-2.0 templating mechanism. I implement some snippet that
I have problem with setting proper charset on my jsf pages. I use MySql
I am working in primefaces 3.3 and jsf 2.0. I have problem in deleting
This is the complete source code: http://www.sendspace.com/file/lwxpyf I have a problem with a JSF
I have some problem's with a simple application in JSF 2.0. I try to
I am new to JSF and have a problem with my simple JSF application.
I have the following problem with the timeouts in Spring Security with JSF: I've
Ok simple question. I have a JSF application, containing a login page. The problem
I have a problem integrating JQuery with JSF. I use Spin. and I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.