You'd like to determine the request headers for a marker of the a4j request. I don't do a4j, but if it is doing its work well, you should be able to determine it based on the X-Requested-With
header.
String requestedWith = request.getHeader("X-Requested-With");
Then just determine in an if
block if the value is the expected one for a4j requests and handle accordingly. Don't forget to continue the filter chain at end whenever neccessary.
if (requestedWith.equals(someAjax4jsfSpecificValue)) {
// Do your job.
}
chain.doFilter(request, response);
To get it to run, just map it on the <servlet-name>
of the FacesServlet
as it is currently definied in web.xml
.
<filter-mapping>
<filter-name>yourFilter</filter-name>
<servlet-name>facesServlet</servlet-name>
</filter-mapping>