jsf 2 - FullAjaxExceptionHandler does not redirect to error page for Ajax request -


i know there has been numerous questions here on question, of them suggest adding following code because there layer "above" fullajaxexceptionhandler sending plain redirect instead of doing ajax redirect (see this similar question):

if ("partial/ajax".equals(request.getheader("faces-request"))) { // jsf ajax request. return special xml response instructs javascript should in turn perform redirect. response.setcontenttype("text/xml"); response.getwriter()     .append("<?xml version=\"1.0\" encoding=\"utf-8\"?>")     .printf("<partial-response><redirect url=\"%s\"></redirect></partial-response>", loginurl); } else {     // normal request. perform redirect usual.     response.sendredirect(loginurl); } 

my question i'm configuring omnifaces's fullajaxexceptionhandler error handling, not have spring security or container managed security intercepting request before fullajaxexceptionhandler can it's thing. can breakpoint fullajaxexceptionhandler , see when following lines of code executed, error page still not being redirected.

string viewid = faces.normalizeviewid(errorpagelocation); viewhandler viewhandler = context.getapplication().getviewhandler(); uiviewroot viewroot = viewhandler.createview(context, viewid); context.setviewroot(viewroot); context.getpartialviewcontext().setrenderall(true);         ...     context.renderresponse(); 

instead, ajax request exception originated has in it's response body:

<?xml version='1.0' encoding='utf-8'?>     <partial-response>         <changes>             <update id="javax.faces.viewroot"><![cdata[<html xmlns="http://www.w3.org/1999/xhtml">... html of error page here ... </html>]]></update>             <update id="javax.faces.viewstate"><![cdata[-3527653129719750158:5595502883804776498]]></update>         </changes>     </partial-response> 

it looks fullajaxexceptionhandler isn't doing it's supposed do, or missing something?

update

attaching browser js output console screen cap.js output console

problem identified

turns out html of error page malformed, contains following snippet, results in mismatched tag error in browser:

<script type="text/javascript"> //<![cdata[ scrollto(0, 0); //]]> </script> 

this seemed have closed cdata tag prematurely. html result of <h:outputscript/> tag, removed since don't need it.

the ajax response looks fine, it's having <update id="javax.faces.viewroot"> containing whole error page document, fullajaxexceptionhandler did job properly.

your concrete problem more caused in client side or in error page document itself, after ajax response has been retrieved. it's javascript's turn parse ajax response , replace current html document accordingly. checking browser's javascript console should give clues problems during step. in particular case, problem seems caused nested cdata block around content rendered <h:outputscript> in turn caused javascript parsing error.

unfortunately, can't reproduce problem mojarra version i've @ hands. perhaps you've somewhere custom/3rd party script renderer who's responsible adding cdata block. script renderer should skip cdata block when partialviewcontext#isajaxrequest() returns true. if still can't figure out, best bet replace <h:outputscript> plain html <script> or remove altogether — did.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -