Why clear cache does not work with all browsers?

859 views Asked by At

I have a JSF application where you enter 2 numbers (index.xhtml), and when you click "Add" button those numbers are added and the result is shown in a new page (resultado.xhtml).

What I want to do is that when you insert the 2 numbers, click "Add" button and go to resultado.xhtml, if you go back to index.xhtml, clicking going back button in you browser, the inputText fields must be empty and not containing the previously inserted values. The problem is that it works with Firefox, but not with Chromium and Konqueror browsers. When I use this browser and press going back button the numbers inserted are in the inputText. How could make it work with all the browsers?

I have followed this link to implement a servlet filter to clear cache: Prevent user from seeing previously visited secured page after logout

index.xhtml

    <h:head>
        <h:outputStylesheet library="css" name="styles.css"  />
    </h:head>
    <h:body>
        <h:form>   

            <!--Number 1 -->
            <h:inputText id="num1" label="num1" required="true" size="5" maxlength="5" 
                    styleClass="#{component.valid ? '' : 'validation-failed'}"
                    value="#{sumaManagedBean.number1}"
                    requiredMessage="You must enter a value"/>
            </h:inputText>
            <h:message for="num1" />


            <!--Number 2-->
            <h:inputText id="num2" label="num2" required="true" size="5" maxlength="5"
                     styleClass="#{component.valid ? '' : 'validation-failed'}"
                     value="#{sumaManagedBean.number2}"
                     requiredMessage="You must enter a value">         
            </h:inputText>
            <h:message for="num2" />

                <h:commandButton value="Add" action="#{sumaManagedBean.direccionPagina()}"/>
        </h:form>


</h:body>  

resultado.xhtml

<h:head>
    <h:outputStylesheet library="css" name="styles.css"  />
</h:head>
<h:body>

<h:outputText value="Add correct" rendered="#{sumaManagedBean.insertCorrecto}" styleClass="message"/> 
    Result:
    <h:outputText value="#{sumaManagedBean.calcularResultado()}" /> 
</h:body>

sumaManagedBean.java. My ManagedBean scope is RequestScope.

package controllers;

//Imports

    @ManagedBean
    @RequestScoped
    public class SumaManagedBean implements Serializable
    {

        boolean m_binsertCorrecto; 

        int number1;
        int number2;

        public SumaManagedBean() {      

        }


        //Getters and Setters
        public int getNumber1() {
            return number1;
        }

        public void setNumber1(int number1) {
            this.number1 = number1;
        }

        public int getNumber2() {
            return number2;
        }

        public void setNumber2(int number2) {
            this.number2 = number2;
        }


        //
        public boolean isInsertCorrecto() 
        {
            return m_binsertCorrecto;
        }

        public void setInsertCorrecto(boolean bInsertCorrecto) 
        {
            this.m_binsertCorrecto = bInsertCorrecto;
        } 



        public int calcularResultado()
        {
            int resultado;

            resultado = number1 + number2;

            return resultado;
        }

        public String direccionPagina()
        {
            String direccion = "/resultado";

            setInsertCorrecto(true);

            return direccion;
        }

    }

NoCacheFilter.java

package filters;

import java.io.IOException;
import javax.faces.application.ResourceHandler;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebFilter("/*") //Apply a filter for all URLs
public class NoCacheFilter implements Filter {

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;

        if (!request.getRequestURI().startsWith(request.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc)
            response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
            response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
            response.setDateHeader("Expires", 0); // Proxies.
        }

        chain.doFilter(req, res);
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }
    @Override
    public void destroy() {
    }
}
0

There are 0 answers