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 planning to do it using Filter).
I'开发者_如何学Cd like to know which method will be executed on my backbean, cause I need to do a dynamic control first.
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>
精彩评论