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 6837589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:29:43+00:00 2026-05-26T23:29:43+00:00

We are using: JSF 1.2-1.2_07-b03-FCS JSTL 1_1-mr2 (special build) Java 1.6.0_22-b04 Eclipse 3.6.0 (Helios)

  • 0

We are using:

  • JSF 1.2-1.2_07-b03-FCS
  • JSTL 1_1-mr2 (special build)
  • Java 1.6.0_22-b04
  • Eclipse 3.6.0 (Helios)
  • Tomcat 6.0.28 (needs to run also on Weblogic)
  • IE 7.0.5730.13
  • Firefox: 6.0

We have mainForm.jsp, filterForm.jsp, and externalForm.jsp views.

There is a button “Filter” on mainForm.jsp to transition to filterForm.jsp. It does that by a navigation rule:

<h:commandButton value="Filter" action="#{mainBean.filterData}" />

The mainBean.java code is:

public String filterData() {
    doStuff();
    return "filter";
}

This initially transitions correctly to filterForm.jsp. We can go back to the mainForm.jsp with the browser back button. We can do this repeatedly.

On mainForm.jsp we have a table (actually an ILog Gantt Chart, but we don’t think that matters), with a “popup” menu on the chart bars. One of the menu options is to redirect to the externalForm.jsp.

Selecting the “redirect” triggers the following method in mainBean.java:

public void redirect(FacesMenuActionEvent event) {
    if (svr == null) {
        svr = new SetupURL(); // Simple code to set up the full URL
    }

    redirectUrl = svr.redirect(event);  // URL of externalForm.jsp
    svr.redirectData(redirectUrl);
}

This correctly works. The window transitions to externalForm.jsp.

If we press the browser back button on externalForm.jsp, we transition back to mainForm.jsp and things look OK.

If we then press the “Filter” button, the code does not execute the filterData() method, but instead it executes the redirect() method and we transition to the externalForm.jsp view, not the filterForm.jsp view.

Why does it do this and how do we force a call to filterData() instead?

******************************************************************************

BalusC - thank you for your solution.  With a few slight tweeks, it worked great.

The changes I made to web.xml are:

    <filter>
       <filter-name>noCacheFilter</filter-name>
       <filter-class>{my package name}.CacheControlFilter</filter-class>
    </filter>
    <filter-mapping>
       <filter-name>noCacheFilter</filter-name>
       <url-pattern>/faces/*</url-pattern>
    </filter-mapping>




Also, I found another solution:

faces-config.xml add:

    <lifecycle>
        <phase-listener id="nocache">{my package name}.
        CacheControlPhaseListener</phase-listener>
    </lifecycle>    


Create file CacheControlPhaseListener.java:

package {my package name};

import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.servlet.http.HttpServletResponse;

public class CacheControlPhaseListener implements PhaseListener {

    public PhaseId getPhaseId() {
        return PhaseId.RENDER_RESPONSE;
    }

    public void afterPhase(PhaseEvent event) {
    }

    public void beforePhase(PhaseEvent event) {
        FacesContext facesContext = event.getFacesContext();
        HttpServletResponse response = (HttpServletResponse) facesContext
                .getExternalContext().getResponse();
        response.addHeader("Pragma", "no-cache");
        response.addHeader("Cache-Control", "no-cache");
        // Stronger according to blog comment below that references HTTP spec
        response.addHeader("Cache-Control", "no-store");
        response.addHeader("Cache-Control", "must-revalidate");
        // some date in the past
        response.addHeader("Expires", "Mon, 8 Aug 2006 10:00:00 GMT");
    }
}

Both seem to work.



Thanks,
John
  • 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-05-26T23:29:44+00:00Added an answer on May 26, 2026 at 11:29 pm

    The browser back button requests the result page from the browser cache. It does not request a fresh new page from the server. In your particular case, most likely the cached page contained a currently invalidated JSF view state.

    Best fix is to instruct the browser to not cache the dynamic JSF pages, but instead requests it straight from the server everytime. You can do that with help of a Filter which has the following lines in the doFilter() method:

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        HttpServletResponse res = (HttpServletResponse) response;
        res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
        res.setHeader("Pragma", "no-cache"); // HTTP 1.0.
        res.setDateHeader("Expires", 0); // Proxies.
        chain.doFilter(request, response);
    }
    

    Map this on the same <servlet-name> of the FacesServlet in web.xml. E.g.

    <filter>
       <filter-name>noCacheFilter</filter-name>
       <filter-class>com.example.NoCacheFilter</filter-class>
    </filter>
    <filter-mapping>
       <filter-name>noCacheFilter</filter-name>
       <servlet-name>facesServlet</servlet-name>
    </filter-mapping>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JSF 2.0 with Facelets in a Java EE 6 application server (GlassFish
I am using JSF 2.0 with eclipse 3.4 and Tomcat6. For Facelets I need
I am writing a web application using JSF 2. I have downloaded mojarra-2.1.3-FCS-binary.zip and
I have a Java application runnning on a Glassfish server using JSF 2.0.2. at
i am using JSF 2.1 ( Mojarra 2.1.0 - FCS ) with tomcat 7
I am developing a Java Web Application using JSF 2.0. Users can upload files.
I am using JSF 2.0 and RichFaces 4. For the date input, I am
I am using JSF 2.0 Mojarra. I need to create a Managed Bean that
I'm using JSF 2.0 and it's new (actually old, but now incorporated in JSF)
I am using JSF 2.0 to develop a pretty big and complex page which

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.