I was able to configure error handing for primefaces using joinfaces and spring-boot 2. Ir order for it to work I extended the PrimeExceptionHandlerFactory to override the method that decides where the error page is according to the thrown exception. This extended error handler is configured on src/main/resources/META-INF/faces-config.xml. This approach also enabled the "p:ajaxExceptionHandler" component functionalities.
In my case, any web.xml configuration was ignored, I think that's because I use the embedded tomcat that provides spring boot. If you are deploying a read .war/.ear application you could just define the error page in the web.xml
This is quite a hack, is would be great if joinfaces could configure this when primefaces is detected, error handling is required in order to create a JSF aplication with primefaces.
Complete working project can be found at: https://github.com/ollbap/my-primefaces-spring-boot-skeleton
See:
faces-config.xml
<?xml version="1.0" encoding="windows-1252"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 2.2//EN"
"http://java.sun.com/dtd/web-facesconfig_2_2.dtd">
<faces-config xmlns="http://java.sun.com/JSF/Configuration">
<name>MyApplication</name>
<ordering>
<before>
<others />
</before>
</ordering>
<application>
<el-resolver>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver</el-resolver>
</application>
<factory>
<exception-handler-factory>es.test.config.ExtendedPrimeExceptionHandlerFactory</exception-handler-factory>
</factory>
</faces-config>
ExtendedPrimeExceptionHandlerFactory.java
package es.test.config;
import java.util.Map;
import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExceptionHandlerFactory;
import org.eclipse.jdt.annotation.Nullable;
import org.primefaces.application.exceptionhandler.PrimeExceptionHandler;
import org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory;
/**
* Extended primefaces exception handler factory in order to create a exception
* handler that redirects to the desired error page.
*/
public class ExtendedPrimeExceptionHandlerFactory extends PrimeExceptionHandlerFactory {
private static final String ERROR_PAGE = "error.xhtml";
public ExtendedPrimeExceptionHandlerFactory(final ExceptionHandlerFactory wrapped) {
super(wrapped);
}
@Override
public ExceptionHandler getExceptionHandler() {
return new ExtendedPrimeExceptionHandler(getWrapped().getExceptionHandler());
}
private static class ExtendedPrimeExceptionHandler extends PrimeExceptionHandler {
public ExtendedPrimeExceptionHandler(ExceptionHandler wrapped) {
super(wrapped);
}
@Override
protected String evaluateErrorPage(@SuppressWarnings("null") Map<String, String> errorPages,
@Nullable Throwable rootCause) {
return ERROR_PAGE;
}
}
}