2

In my application the user should be redirected to a custom error-page when a specific exeption is thrown.

The error-page is shown but the URL doesnt change to the error-page location.

Following are the relevant code snipplets

inside my web.xml I have the following declarations.

<error-page>
    <exception-type>de.mmo.base.util.login.NoSidException</exception-type>
    <location>/error/NoActiveSID.xhtml</location>
</error-page>
<error-page>
    <exception-type>de.mmo.exceptions.NotLoggedInException</exception-type>
    <location>/error/NotLoggedInExc.xhtml</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>/error/error404.xhtml</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/error/error500.xhtml</location>
</error-page>

In my faces-config.xml I tried the following two declarations

<factory>                                                             
    <exception-handler-factory>                                       
        org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory
    </exception-handler-factory>                                  
</factory>

and

<factory>
    <exception-handler-factory>
        de.mmo.test.MyExceptionHandlerFactory
    </exception-handler-factory>
</factory>      

When I tried with MyExceptionHandler I commented the FullAjaxExceptionHandlerFactory out.

Following is the MyExceptionHandler code

public class MyExceptionHandlerFactory extends ExceptionHandlerFactory {

    private ExceptionHandlerFactory parent;

    public MyExceptionHandlerFactory(ExceptionHandlerFactory parent) {
        this.parent = parent;
    }

    @Override
    public ExceptionHandler getExceptionHandler() {
        ExceptionHandler result = parent.getExceptionHandler();
        result = new MyExceptionHandler(result);

        return result;
    }

}        

public class MyExceptionHandler extends FullAjaxExceptionHandler {


    private ExceptionHandler wrapped;

    public MyExceptionHandler(ExceptionHandler wrapped) {
        super(wrapped);
        this.wrapped = wrapped;
    }

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

    @Override
    protected String findErrorPageLocation(FacesContext context,
        Throwable exception) {
        System.out.println("inside my findErrorPageLocation");
        if(exception instanceof NoSidException) {
            System.out.println("inside exception instanceof NoSidExceptin");
            return "/error/NoActiveSID.xhtml?faces-redirect=true";
    } else {
        return super.findErrorPageLocation(context, exception);
    }
}    

And last I have e.g. the NoSidExceptino class

public class NoSidException extends FacesException {
    private static final long serialVersionUID = -2350480134523249331L;
    public NoSidException(){
        super ("ACHTUNG: SID ist abgelaufen !");
    }
}

The error pages are all in webapp --> error --> *.xhtml files

My application is running on a glassfish server.

If you need more informations I will tell them :)

thx for help

----------EDIT---------------------------------------------------------------

I was able to solve my problem with javascript.

In the header of the error-page i insert

<script type="text/javascript">
    $(document).load(function() {
    redirectToErrorPage (); 
    });            
</script>

And in the body I have a remoteCommand

<h:form>
    <p:remoteCommand name="redirectToErrorPage" action="#{nav.baueNavPfad(pfadKonst.ERROR_NOSID, false)}">
    </p:remoteCommand>
</h:form>
Arthur Welsch
  • 269
  • 2
  • 15
  • It is not redirecting when you cause the exception through "classic" navigation or when using Ajax calls? – SJuan76 Sep 16 '15 at 07:42
  • Hi SJuan76, the exception is thrown through ajax calls. For this I used the org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory – Arthur Welsch Sep 16 '15 at 08:07
  • For additional information: in my web.xml I have the following declaration javax.faces.PROJECT_STAGE Production – Arthur Welsch Sep 16 '15 at 08:08

0 Answers0