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

  • SEARCH
  • Home
  • 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 8048471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:27:00+00:00 2026-06-05T06:27:00+00:00

I am using ExternalContext.redirect(String); method to redirect user to another page: FacesContext.getCurrentInstance().addMessage(new FacesMessage(Bla bla

  • 0

I am using ExternalContext.redirect(String); method to redirect user to another page:

FacesContext.getCurrentInstance().addMessage(new FacesMessage("Bla bla bla..."));
FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(ec.getRequestContextPath() + "/scenario.xhtml");

As Matt Handy mentioned in his answer, I used Flash.setKeepMessages(true); but it does not seem to work with ExternalContext.redirect. (Although it works when I redirect by returning a page name from bean’s action method.)

Now how can I add FacesMessage so that it is visible in the redirected (scenario.xhtml) page?

  • 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-05T06:27:01+00:00Added an answer on June 5, 2026 at 6:27 am

    This seems to be a timing problem. This listener method is invoked during the preRenderView event. According to the source code of ELFlash (Mojarra’s Flash implementation as returned by ExternalContext#getFlash()) it turns out that it won’t set the flash cookie when you’re currently sitting in the render response phase and the flash cookie hasn’t been set yet for the current request:

    Here are the relevant lines from ELFlash:

    if (currentPhase.getOrdinal() < PhaseId.RENDER_RESPONSE.getOrdinal()) {
        flashInfo = flashManager.getPreviousRequestFlashInfo();
    } else {
        flashInfo = flashManager.getNextRequestFlashInfo(this, true);
        maybeWriteCookie(context, flashManager);
    }
    

    The maybeWriteCookie would only set the cookie when the flash cookie needs to be passed through for the second time (i.e. when the redirected page in turn redirects to another page).

    This is an unfortunate corner case. This ELFlash logic makes sense, but this isn’t what you actually want. Basically you need to add the message during INVOKE_APPLICATION phase instead. There is however no such event as postInvokeAction. With the new JSF 2.2 <f:viewAction> tag it should be possible as it really runs during invoke application phase.

    <f:viewAction action="#{bean.onload}" />
    

    As long as you’re not on JSF 2.2 yet, you’d need to look for alternate ways. The easiest way would be to create a custom ComponentSystemEvent.

    @NamedEvent(shortName="postInvokeAction")
    public class PostInvokeActionEvent extends ComponentSystemEvent {
    
        public PostInvokeActionEvent(UIComponent component) {
            super(component);
        }
    
    }
    

    Now you need somewhere a hook to publish this event. The most sensible place is a PhaseListener listening on after phase of INVOKE_APPLICATION.

    public class PostInvokeActionListener implements PhaseListener {
    
        @Override
        public PhaseId getPhaseId() {
            return PhaseId.INVOKE_APPLICATION;
        }
    
        @Override
        public void beforePhase(PhaseEvent event) {
            // NOOP.
        }
    
        @Override
        public void afterPhase(PhaseEvent event) {
            FacesContext context = FacesContext.getCurrentInstance();
            context.getApplication().publishEvent(context, PostInvokeActionEvent.class, context.getViewRoot());
        }
    
    }
    

    If you register it as follows in faces-config.xml

    <lifecycle>
        <phase-listener>com.example.PostInvokeActionListener</phase-listener>
    </lifecycle>
    

    then you’ll be able to use the new event as follows

    <f:event type="postInvokeAction" listener="#{bean.onload}" />
    

    Update this is also available in the JSF utility library OmniFaces, so you don’t need to homebrew the one and other. See also the InvokeActionEventListener showcase example.

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

Sidebar

Related Questions

Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
Using devise 2.1.0 I am trying to send the new registration page a PricingPlan
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using WebViewBrush I can render web page content (it's screen shot) to e.g. Rectangle
I have the following code in javascript: <script type=text/javascript src=#{facesContext.externalContext.requestContextPath}/js/sample-points.js></script> <script type=text/javascript>//<![CDATA[ var cloudmade
I'm using a captcha in my JSF page (not recaptcha or randomly generated image
In JSF1 you can access the bean instances of your current FacesContext by ExternalContext
I saw that ExternalContext in JSF 2.0 has a method setResponseStatus, how can I
I have a JSF page (using MyFaces 2.0) that does a bit of data

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.