0

I searched almost every question about FullAjaxExceptionHandler here and none of them solved my problem.

Well, I have implemented FullAjaxExceptionHandler but it isn't working with ajax requests. If the request isn't Ajax it works OK and redirect to the expired page, but if it's Ajax, the page goes blank and I got:

FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request.  Error page '/view/errorpages/expired.faces' will be shown.
javax.faces.application.ViewExpiredException: viewId:/view/main.faces - A exibição de /view/main.faces não pôde ser restaurada.
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:200)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:111)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.omnifaces.filter.CacheControlFilter.doFilter(CacheControlFilter.java:226)
at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.omnifaces.filter.FacesExceptionFilter.doFilter(FacesExceptionFilter.java:56)
at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)

p.s. I'm sure I'm not redirecting it manually elsewhere.

EDIT: I tried an approach with a custom ViewExpiredException

public class ViewExpiredException extends ExceptionHandlerWrapper {

private ExceptionHandler wrapped;

public ViewExpiredException(ExceptionHandler wrapped) {
    this.wrapped = wrapped;
}

@Override
public ExceptionHandler getWrapped() {
    return this.wrapped;
}

@Override
public void handle() throws FacesException {

    for (Iterator<ExceptionQueuedEvent> iter = getUnhandledExceptionQueuedEvents()
            .iterator(); iter.hasNext();) {
        ExceptionQueuedEvent evt = iter.next();
        Throwable exception = evt.getContext().getException();
        FacesContext fc = evt.getContext().getContext();
        if (exception instanceof javax.faces.application.ViewExpiredException) {

            try {
                fc.getExternalContext().redirect("/sino/view/main.xhtml");
                fc.responseComplete();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                iter.remove();
            }
        }
    }
    getWrapped().handle();
   }

}

And it works for both Ajax and non-Ajax request. But i still would like to use the omnifaces approach

UPDATE After changing some log, I've got this msg when the page goes blank after redirect:

Warning: you have included the Google Maps API multiple times on this page. This may cause unexpected errors.              main.js.53

I dont think this is the problem but I also don't know why with FullAjaxExceptionHandler it happens and with ViewExpiredException doesn't.

Edit2: Now expired.xhtml is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:t="http://myfaces.apache.org/tomahawk"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html" xml:lang="pt" lang="pt">
<ui:composition>
    <h:form>
        <h:outputText value="View Expired" />
    </h:form>
</ui:composition>
</html>

And I'm still not redirected, but now the page doesn't goes blank. The page stays at the same page and i got:

Uncaught TypeError: Cannot read property '0' of null             primefaces.js.faces?ln=primefaces:1

Maybe a problem before the redirect?

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
Shadi
  • 57
  • 2
  • 9
  • Check the HTTP traffic monitor and JS console. Did everything went as it should be? – BalusC Apr 03 '14 at 20:20
  • I guess i got a weird situation here. When the redirect worked i've got a javascript error, but when the redirect didnt worked the page goes blank and no errors are shown. I'll edit with pics to show you. – Shadi Apr 04 '14 at 19:22
  • Well, actually i cant post images due my reputation. – Shadi Apr 04 '14 at 19:26
  • I tried a simple approach with a custom ViewExpiredException. I'll edit the post for more info. – Shadi Apr 04 '14 at 21:47
  • Apparently your error page contains a JS error. To exclude one and other, start with a completely blank error page with a simple text "Error" or so. If that indeed works, then just build up to the desired full error page step by step until it breaks again. The cause should then have identified itself. – BalusC Apr 07 '14 at 21:53

1 Answers1

1

I was having the same problem, after removing some tag elements it worked. Try redirecting to a page without tags that uses namespaces to see if it works.

Lucas Dimas
  • 129
  • 1
  • 8