2013-08-01 3 views
6

Donc, après avoir été confronté à la redoutée javax.faces.application.ViewExpiredException, je devais aller chercher autour d'Internet pour trouver la bonne solution. Heureusement, les solutions sont facilement disponibles et je suis allé de l'avant et adopté les OmniFaces FullAjaxExceptionHandler. Assez dit, comme avec presque tout d'OmniFaces, cela a fonctionné à merveille. Mais, chaque fois que je l'ai vue expirant j'obtiens:Silence FullAjaxExceptionHandler

SEVERE: WebModule[/myModule]FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/WEB-INF/errorpages/test.xhtml' will be shown. 
javax.faces.application.ViewExpiredException: viewId:/my/page.xhtml - View /my/page.xhtml could not be restored. 
... 

Ceci est très bien comme elle est gérée comme prévu, mais est là de toute façon de faire taire cette exception d'être imprimé à la server.log? Cela encombrerait le journal assez rapidement.

Je courais:
Mojarra 2.1.23
PrimeFaces 4.0 INSTANTANÉ
OmniFaces 1.6-SNAPSHOT-2013-07-01

sur
Glassfish 3.1.2.2

Répondre

6

Comme par OmniFaces 1.6, vous pouvez l'étendre et remplacer la méthode logException() comme ci-dessous pour ignorer la trace de pile pour ViewExpiredException.

public class YourAjaxExceptionHandler extends FullAjaxExceptionHandler { 

    public YourAjaxExceptionHandler(ExceptionHandler wrapped) { 
     super(wrapped); 
    } 

    @Override 
    protected void logException(FacesContext context, Throwable exception, String location, String message, Object... parameters) { 
     if (exception instanceof ViewExpiredException) { 
      // With exception==null, no trace will be logged. 
      super.logException(context, null, location, message, parameters); 
     } 
     else { 
      super.logException(context, exception, location, message, parameters); 
     } 
    } 

} 

Créer une usine autour:

public class YourAjaxExceptionHandlerFactory extends ExceptionHandlerFactory { 

    private ExceptionHandlerFactory wrapped; 

    public YourAjaxExceptionHandlerFactory(ExceptionHandlerFactory wrapped) { 
     this.wrapped = wrapped; 
    } 

    @Override 
    public ExceptionHandler getExceptionHandler() { 
     return new YourAjaxExceptionHandler(getWrapped().getExceptionHandler()); 
    } 

    @Override 
    public ExceptionHandlerFactory getWrapped() { 
     return wrapped; 
    } 

} 

Afin d'obtenir ce à courir, inscrivez-vous comme usine de faces-config.xml la manière habituelle (ne pas oublier de retirer l'enregistrement original pour FullAjaxExceptionHandlerFactory) :

<factory> 
    <exception-handler-factory>com.example.YourExceptionHandlerFactory</exception-handler-factory> 
</factory> 
+0

Vous êtes un bon monsieur et un érudit! Merci beaucoup. – blo0p3r

+0

@BalusC un commutateur est manquant dans 'MyAjaxExceptionHandler # logException'. Cette ligne doit être dans l'autre: 'super.logException (contexte, exception, emplacement, message, paramètres);'. De plus, si je ne me trompe pas, le fichier faces-config.xml '' doit être com.example.MyAjaxExceptionHandlerFactory. –

+0

@Patrick: la réponse a été mise à jour. Merci! – BalusC

Questions connexes