2013-08-01 9 views
6

Quindi, dopo essere stato confrontato con il temuto javax.faces.application.ViewExpiredException, ho dovuto cercare su Internet per trovare la soluzione adeguata. Fortunatamente, le soluzioni sono prontamente disponibili e sono andato avanti e ho adottato OmniFaces FullAjaxExceptionHandler.Silence FullAjaxExceptionHandler

Detto abbastanza, come con praticamente tutto da OmniFaces, ha funzionato a meraviglia. Ma, ogni volta che ho una vista in scadenza sto ottenendo:

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. 
... 

Questo va bene in quanto è gestita come previsto, ma Esiste un modo per mettere a tacere questa eccezione da essere stampato al server.log? Questo affollerebbe il log abbastanza rapidamente.

Sono in esecuzione:
Mojarra 2.1.23
primefaces 4.0-SNAPSHOT
OmniFaces 1.6-SNAPSHOT-2013-07-01

su
Glassfish 3.1.2.2

risposta

6

Come da OmniFaces 1.6, è possibile estenderlo e sovrascrivere il metodo logException() come indicato di seguito per saltare la traccia dello stack per 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); 
     } 
    } 

} 

Crea una fabbrica intorno ad esso:

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; 
    } 

} 

Al fine di ottenere questo per funzionare, registrarlo come fabbrica in faces-config.xml solito modo (non dimenticare di rimuovere la registrazione originale per FullAjaxExceptionHandlerFactory) :

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

Il buon signore è un gentiluomo e uno studioso! Grazie molto. – blo0p3r

+0

@BalusC manca un parametro in 'MyAjaxExceptionHandler # logException'. Questa linea deve essere all'interno di altro: 'super.logException (contesto, eccezione, posizione, messaggio, parametri);'. Inoltre, se non sbaglio, faces-config.xml '' deve essere com.example.MyAjaxExceptionHandlerFactory. –

+0

@Patrick: la risposta è stata aggiornata. Grazie! – BalusC

Problemi correlati