Custom JSF ExceptionHandler does not work

UI Components for JSF
Post Reply
Andrewsss
Posts: 1
Joined: 12 Jan 2021, 09:43

12 Jan 2021, 09:44

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().Target Pay and Benefits();
}
}
The faces-config.xml:

...
<lifecycle>
<phase-listener>
hu.magnet.vv.fe.exception.AjaxLoginListener
</phase-listener>
</lifecycle>
...
Last edited by Andrewsss on 18 Jan 2021, 11:55, edited 1 time in total.

NOTiFY
Posts: 393
Joined: 25 May 2016, 22:57

12 Jan 2021, 11:21

It would be useful to:

1. Show your WildFly output from the logs (FATAL ERROR, WARNING INFO, DEBUG, TRACE) from your 'Custom JSF ExceptionHandler does not work'

from:

Code: Select all

MacBook-Pro-2:bin NOTiFY$ ./standalone.sh -b 0.0.0.0 --server-config=standalone-full.xml
=========================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: /usr/local/Cellar/wildfly-as/wildfly-21.0.2.Final

  JAVA: /Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home/bin/java

  JAVA_OPTS:  -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true  --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED

=========================================================================

08:08:36,102 INFO  [org.primefaces.webapp.PostConstructApplicationEventListener] (ServerService Thread Pool -- 85) Running on PrimeFaces 8.0.5

etc. etc.  ...

2. Which versions of PrimeFaces, WildFly, JDK etc. are you using? Add to your 'Viewing profile -> Edit signature'

3. Use the layout to configure on your question (Quote text, Code Display etc.) as listed in: [PLEASE READ BEFORE POSTING] viewtopic.php?f=3&t=1194
PF 13.0.0--Jakarta. Jakarta Faces 4.0.1/Kotlin Multiplatform 1.9.10
Mojarra 4.0.2, OmniFaces 4.2
WildFly 29.0.1.Final 'preview' Jakarta EE 10.0.0
JDK 20.0.2, Kotlin 1.9.10, Gradle 8.3 Groovy DSL, MongoDB 7.0.0
IntelliJ IDEA 2023.2.1, macOS Ventura 13.5.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 28 guests