Glassfish v3 üzerinde bir JSF 2.0 uygulaması geliştiriyorum ve ViewExpiredException işlemeye çalışıyorum. Ama ne yaparsam yapayım, kendi hata sayfam yerine her zaman bir Glassfish hata raporu alırım. VEE'nin oluşumunu simüle etmek için, aşağıdaki işlevi VEE'yi ateşleyen destek fasulyem içine soktum. Bu işlevi JSF sayfamdan bir commandLink aracılığıyla tetikliyorum. Kodu:JSF: ViewExpiredException yakalanamıyor
@Named
public class PersonHome {
(...)
public void throwVEE() {
throw new ViewExpiredException();
}
}
ilk ben sadece benim web.xml bir hata-sayfa ekleyerek denedim At
:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/error.xhtml</location>
</error-page>
Ama bu işe yaramazsa, ben hata yönlendirildi değilim denedim
description:The server encountered an internal error() that prevented it from fulfilling this request.
exception: javax.servlet.ServletException: javax.faces.application.ViewExpiredException
root cause: javax.faces.el.EvaluationException:javax.faces.application.ViewExpiredException
root cause:javax.faces.application.ViewExpiredException
sonraki şey ExceptionHandlerFactory ve CustomExceptionHandler olarak des yazmaktı: ama şu içeriğe sahip bir HTTP Durum 500 sayfa gösterir Glassfish errorpage, gösterilen ediyorum JavaServerFaces 2.0 - Complete Reference numaralı belgedir. Bu sınıflar
<factory>
<exception-handler-factory>
exceptions.ExceptionHandlerFactory
</exception-handler-factory>
</factory>
Ve ekledi: Yani ben yüzler-config.xml içine aşağıdaki etiketi takılı fabrika:
package exceptions;
import javax.faces.context.ExceptionHandler;
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;
}
}
özel durum işleyicisi:
package exceptions;
import java.util.Iterator;
import javax.faces.FacesException;
import javax.faces.application.NavigationHandler;
import javax.faces.application.ViewExpiredException;
import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExceptionHandlerWrapper;
import javax.faces.context.FacesContext;
import javax.faces.event.ExceptionQueuedEvent;
import javax.faces.event.ExceptionQueuedEventContext;
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, "/login?faces-redirect=true");
fc.renderResponse();
} finally {
i.remove();
}
}
}
// At this point, the queue will not contain any ViewExpiredEvents.
// Therefore, let the parent handle them.
getWrapped().handle();
}
}
Ama HALA Hata sayfama yönlendirilmedi - Yukarıdaki gibi aynı HTTP 500 hatası alıyorum. Neyi yanlış yapıyorum, uygulamada özel durumun doğru şekilde ele alınmadığı konusunda eksik olan ne olabilir? 'un herhangi biri çok takdir edilmiş!
Tamam
DÜZENLEME i dürüstüm. Aslında, kodum aslında Scala'da yazılmış, ama bu uzun bir hikaye. Her zaman bir Java sorunu olduğunu düşündüm. Bu durumda GERÇEK hata kendi aptallığımdı. (Scala) kodumda, CustomExceptionHandler'da, satırı "i.remove();" ile eklemeyi unuttum. Böylece ViewExpiredException, işlem yaptıktan sonra UnhandledExceptionsQueue içinde kaldı ve "köpürdü". Ve ne zaman havalanırsa, bir ServletException olur.
İkinizi de karıştırdığınız için gerçekten üzgünüm!
* *: Eğer 1 örnekte olduğu gibi bir fasulye içindeki bunu varsayılan olarak, bu bir 'FacesException' sarılmış ve o-ecek edilecek beklenen hata sayfasında bitmez. – BalusC
Teşekkürler. Haklısın, jSF-phase ifadesini son düzenlememden kaldırdım. – ifischer
Son düzenlediğiniz yayın işe yarıyor mu? Düşünceleriniz için ViewExpired hatasında –