4 Replies Latest reply on Oct 13, 2007 4:54 AM by Terry

    Disabling browser cache ???

    Terry Apprentice


      Anyone knows how to set response header in Seam/JSF to stop browser cache?

      I have a problem which is turing out to be a pain. Say I have a JSF page to view a record, then I delete it. But everytime I bring up view page, it still shows the record, even though its been deleted from the database.

      I believe this to be a common problem, yet I can't find any solution.

      I use default RHDS set up with JBoss AS 4.2.0.

        • 1. Re: Disabling browser cache ???
          Pete Muir Master

          Probably your best bet is to use a filter which adds a header to the response object.

          • 2. Re: Disabling browser cache ???
            Terry Apprentice


            Thanks. I tried following? it executs but it gets invoked many time for each page. I think once or so for every included xhtml, since my page has template, headers, footer, menu bars in seperate files. I guess that is normal...


            public class NoCachePhaseListener implements PhaseListener {
            
             public PhaseId getPhaseId() {
             return PhaseId.RENDER_RESPONSE;
             }
            
             public void afterPhase(PhaseEvent phaseEvent) {
             }
            
             public void beforePhase(PhaseEvent phaseEvent) {
            
             FacesContext facesContext = phaseEvent.getFacesContext();
             HttpServletResponse response = (HttpServletResponse)facesContext.getExternalContext().getResponse();
            
             try{
             response.setHeader("Cache-Control", "no-cache, must-revalidate");
             response.setDateHeader("Expires", 0L);
             response.setHeader("Pragma", "No-cache");
             }catch(NullPointerException npe){
             System.out.println("Null http response, no action on cache-control");
             }
            
             }
            }



            faces-config.xml:

            <lifecycle>
             <phase-listener>au.edu.tisc.util.NoCachePhaseListener</phase-listener>
            </lifecycle>





            • 3. Re: Disabling browser cache ???
              Lisa Mark Newbie

               

              "terryb" wrote:

              Anyone knows how to set response header in Seam/JSF to stop browser cache?

              I have a problem which is turing out to be a pain. Say I have a JSF page to view a record, then I delete it. But everytime I bring up view page, it still shows the record, even though its been deleted from the database.

              I believe this to be a common problem, yet I can't find any solution.

              I use default RHDS set up with JBoss AS 4.2.0.



              I think its not with browser cache but with your view rendering. Check whether your action method outcome returns no 'null', instead return empty string "", then the page would be rendered new.

              • 4. Re: Disabling browser cache ???
                Terry Apprentice

                Thanks Lisa, yes my action was not returning empty string.