0

I have a JSF application, with PrimeFaces. My app run on WildFly

I mus redirect the user to the login page, if the session expired. I have written an CustomExceptionHandler:

The ExceptionHandlerFactory:

public class ExceptionHandlerFactory extends javax.faces.context.ExceptionHandlerFactory {

private javax.faces.context.ExceptionHandlerFactory parent;

public ExceptionHandlerFactory(javax.faces.context.ExceptionHandlerFactory parent) {
    this.parent = parent;
}

@Override
public ExceptionHandler getExceptionHandler() {
    ExceptionHandler result = parent.getExceptionHandler();
    result = new CustomExceptionHandler(result);
    return result;
}

}

The ExceptionHandlerWrapper:

class CustomExceptionHandler extends ExceptionHandlerWrapper {

private ExceptionHandler parent;

public CustomExceptionHandler(ExceptionHandler parent) {
    this.parent = parent;
}

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

@Override
public void handle() throws FacesException {
    for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) {
        ExceptionQueuedEvent event = i.next();
        System.out.println("Iterating over ExceptionQueuedEvents. Current:" + event.toString());
        ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
        Throwable t = context.getException();
        if (t instanceof ViewExpiredException) {
            ViewExpiredException vee = (ViewExpiredException) t;
            FacesContext fc = FacesContext.getCurrentInstance();

            NavigationHandler nav =
                    fc.getApplication().getNavigationHandler();
            try {
                // Push some useful stuff to the flash scope for
                // use in the page
                fc.getExternalContext().getFlash().put("expiredViewId", vee.getViewId());

                nav.handleNavigation(fc, null, "/index.xhtml");
                fc.renderResponse();

            } finally {
                i.remove();
            }
        }
    }
    // At this point, the queue will not contain any ViewExpiredEvents.
    // Therefore, let the parent handle them.
    getWrapped().handle();
}
}

The faces-config.xml:

...
<factory>
    <exception-handler-factory>
        hu.****.**.fe.exception.ExceptionHandlerFactory
    </exception-handler-factory>
</factory>
...

When the session expired, not the Login page come, only this page:

<partial-response>
<changes>
<update id="javax.faces.ViewRoot">
<html***the content of the index.xhtml (login page)</html>
</update>
<update id="j_id1:javax.faces.ViewState:0">-2214895618242088710:6470920362668814776</update>
</changes>
</partial-response>

Please help, what's wrong with the code.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Károly Neue
  • 89
  • 2
  • 9

0 Answers0