How to implement no caching on JSF pages
Tech-Today

How to implement no caching on JSF pages


Currently there are 2 ways I know that can do this.

1.) By implementing Filter and manually overriding the cache controls. See code below (note: not my original I found this somewhere else long time ago):

@WebFilter(servletNames = { "Faces Servlet" })
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() {

}

}

2.) The one I preferred, using omnifaces' CacheControlFilter. More information available at: http://showcase.omnifaces.org/filters/CacheControlFilter. To use just need to add the filter and integrate with facesServlet.

<filter>
<filter-name>noCache</filter-name>
<filter-class>org.omnifaces.filter.CacheControlFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>noCache</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>




- How To Call A Javaee Rest Web Service With Basic Authentication Using Jquery Ajax
I don't really remember when I coded it, nor where I got it but I'm writing it here for future use :-) Below is the code I use to test CORS, http://en.wikipedia.org/wiki/Cross-origin_resource_sharing. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>...

- How To Add Javaee 6 Archetypes In Eclipse Kepler
I'm currently playing with the latest release from eclipse (kepler) and found out that the maven archetypes for JavaEE6 are missing. Perhaps the maven catalog is not outdated, to do so follow the following steps: 1.) Run eclipse kepler 2.) Open Window->Preferences,...

- Using Shiro's Native And The Default Http Session
Currently I've been working on a project that uses shiro for authentication and authorization. I can say that aside from the fact that it doesn't support jsf, it's a very useful tool. This page contains codes that will help you in configuring...

- Using Ejb3.1 As The Backing Bean For Jsf Using Cdi (jsr-330)
This tutorial assumes that you already have knowledge on EJB, JSF, maven and injection. These are the steps as well as the code I use to make it work. 1.) Create 2 maven projects (web, ejb - has HelloBean class) 2.) 2.) In the web part we need to create...

- Creating Your First Enterprise Application Project On Eclipse-jee-helios
First you should create an ejb project as specified here: http://czetsuya-tech.blogspot.com/2011/03/creating-your-first-ejb3-project-in.html Take note that my interface were inside the ejb project. You can pull that out and place in its own project ipielEJB2Client....



Tech-Today








.