Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
rated 0 times [  131] [ 6]  / answers: 1 / hits: 15617  / 14 Years ago, thu, february 3, 2011, 12:00:00

I am using JSF framework in my application. I need to run a specific script before the render response phase in my Phase Listener class.

Condition for running this script is that, if the request triggered is a Ajax request i need to run the script, if the request triggered is a Http request i should not run that script.

Can anyone please help me to differentiate the requests recieved.?

More From » java


Ajax requests have usually a X-Requested-With: XMLHttpRequest request header. In JSF, you can obtain the request headers by ExternalContext#getRequestHeaderMap().

ExternalContext externalContext = facesContext.getExternalContext();
Map<String, String> headers = externalContext.getRequestHeaderMap();
boolean ajax = XMLHttpRequest.equals(headers.get(X-Requested-With));

[#93922] Tuesday, February 1, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 518
Total Questions: 81
Total Answers: 96

Location: Aland Islands
Member since Wed, Nov 17, 2021
3 Years ago