0

I make a partial ajax request from a page and if I don't get a partial ajax response as response or if the partial ajax response is malformed I cannot find a way to handle it. Client side just make no actions in such cases and just stays cool.
It happens when session is expired and server returns non ajax response (without <partial-response> tag) instead of ajax response or when an exception is trown so <partial-response> becomes malformed and has no ending tag.
Any idea?
I tried to override PrimeFaces.ajax.Response.handle function on the client side but it's not called in such cases (because non ajax response is returned).

Rustam
  • 241
  • 4
  • 13
  • What exactly happens when session is expired? Is some security thing or exception handler thing then performing a redirect via `response.sendRedirect(url)` or so? *That* part needs to be fixed in order to be able to deal with JSF ajax requests. – BalusC Feb 13 '15 at 08:45
  • When session is expired container returns login page as regular http response and clijent side do nothing in that case because it expects partial response I gues. I got suggestion from my colleague to put some java jsp code in login page which will check what kind of request it is and if it is ajax then return error status. On clinet side need to be javascript to check respnse status and if it's error then reload or redirect page to login. – Rustam Feb 13 '15 at 09:21
  • Is this acceptable as dupe? http://stackoverflow.com/questions/12504131/viewexpiredexception-not-thrown-on-ajax-request-if-jsf-page-is-protected-by-j-se/ – BalusC Feb 13 '15 at 09:25
  • It is more clear what happens now. I think I have the case you are described: "Note that if the login page were not a JSF page (e.g. JSP or plain HTML), then the ajax request would have returned the whole HTML output of the page as ajax response which is unparseable by JSF ajax and interpreted as "empty" response." My login page is JSP and PhaseListener is not involved here. – Rustam Feb 13 '15 at 10:03

1 Answers1

0

And solution is to put this java code in login.jsp page to identify ajax requests

<%
    boolean ajax = "XMLHttpRequest".equals( request.getHeader( "X-Requested-With" ) );
    if ( ajax ) {
        // Authentication Timeout
        response.setStatus( 419 );
    }
%>

and jQuery on client side (e.g. in some template)

<script>
$.ajaxSetup({
    statusCode: {
      419: function() {
          location.reload();
      }
    }
   })
</script>
Rustam
  • 241
  • 4
  • 13