Добавить обработчик обработчика исключений, который обрабатывает исключения и перенаправляет или пересылает страницу ошибки или страницу входа.
Хорошая регистрация в этом поможет вам легко найти ошибку и поможет вам решить проблему раньше.
web.xml:
<factory>
<exception-handler-factory>com.framework.exceptionmgmt.CustomExceptionHandlerFactory</exception-handler-factory>
</factory>
завод:
@Override
public ExceptionHandler getExceptionHandler() {
return new CustomExceptionHandler(wrapped.getExceptionHandler());
}
/**
* Returns the wrapped factory.
*/
@Override
public ExceptionHandlerFactory getWrapped() {
return wrapped;
}
обработчик:
@Override
public void handle() throws FacesException {
for (final Iterator<ExceptionQueuedEvent> it = getUnhandledExceptionQueuedEvents().iterator(); it.hasNext();) {
Throwable t = it.next().getContext().getException();
System.out.println("Exception in page: "+t.getMessage());
while ((t instanceof FacesException || t instanceof EJBException || t instanceof ELException) && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof FileNotFoundException || t instanceof ViewExpiredException) {
final ExternalContext externalContext = facesContext.getExternalContext();
final Map<String, Object> requestMap = externalContext.getRequestMap();
try {
// Log the information in the logs
String message;
if (t instanceof ViewExpiredException) {
final String viewId = ((ViewExpiredException) t).getViewId();
message = "View is expired. <a href='/ifos" + viewId + "'>Back</a>";
} else {
message = t.getMessage(); // beware, don't leak internal
// info!
}
requestMap.put("errorMsg", message);
try {
HttpServletRequest origRequest = (HttpServletRequest) facesContext.getExternalContext()
.getRequest();
String requestedURL = origRequest.getRequestURL().toString();
resetResponse(facesContext);
redirectToCorrectPage(origRequest.getContextPath()+"/error.xhtml",facesContext);
} catch (final IOException e) {
}
facesContext.responseComplete();
} finally {
it.remove();
}
}else{
try {
resetResponse(facesContext);
Map<String, Object> sessnMap = FacesContext
.getCurrentInstance().getExternalContext()
.getSessionMap();
// For checking whether user is logged in or not If not then redirect to login page instead of error page
Boolean isUserLoggedIn = (Boolean) sessnMap
.get("isUserLoggedIn");
if (isUserLoggedIn == null || !isUserLoggedIn) {
redirectToCorrectPage(
((HttpServletRequest) facesContext
.getExternalContext().getRequest()).getContextPath()
+ "/error.xhtml",
facesContext);
} else {
redirectToCorrectPage(
((HttpServletRequest) facesContext
.getExternalContext().getRequest()).getContextPath()
+ "/error.xhtml",
facesContext);
}
} catch (final IOException e) {
}finally {
it.remove();
}
facesContext.responseComplete();
}
}
у вас есть <обработчика исключений-завод> в лицах-config.xml? –
@BalusC однажды я увидел действительно плохой пользовательский, и все прошло через фильтр. после исправления отладки стало легко –
@MahendranAyyarsamyKandiar нет, не знаю. –