views:

25

answers:

1

Does anybody know how to intercept a a4j request using a javax.servlet.Filter? The interception must occur before FacesServlet be called (it's why I'm planing to do it using Filter). I'd like to know wich method will be executed on my backbean, cause I need to do a dynamic control first.

Tks!

A: 

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>
BalusC