Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
106 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
03-Login/src/main/java/org/agoncal/sample/jsf/login/utils/CatchException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.agoncal.sample.jsf.login.utils; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.interceptor.InterceptorBinding; | ||
|
||
/** | ||
* @author Antonio Goncalves | ||
* http://www.antoniogoncalves.org | ||
* -- | ||
* Any JSF backing bean using this interceptor binding will catch and display exceptions on the JSF page | ||
*/ | ||
|
||
@InterceptorBinding | ||
@Target({METHOD, TYPE}) | ||
@Retention(RUNTIME) | ||
public @interface CatchException { | ||
} |
41 changes: 41 additions & 0 deletions
41
03-Login/src/main/java/org/agoncal/sample/jsf/login/utils/CatchExceptionInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.agoncal.sample.jsf.login.utils; | ||
|
||
import static javax.faces.application.FacesMessage.SEVERITY_ERROR; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.faces.application.FacesMessage; | ||
import javax.faces.context.FacesContext; | ||
import javax.inject.Inject; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
/** | ||
* @author Antonio Goncalves - http://www.antoniogoncalves.org | ||
* | ||
* This interceptor catches exception and displayes them in a JSF page | ||
*/ | ||
|
||
@Interceptor | ||
@CatchException | ||
public class CatchExceptionInterceptor implements Serializable | ||
{ | ||
|
||
@Inject | ||
private FacesContext context; | ||
|
||
@AroundInvoke | ||
public Object catchException(InvocationContext ic) throws Exception | ||
{ | ||
try | ||
{ | ||
return ic.proceed(); | ||
} | ||
catch (Throwable e) | ||
{ | ||
context.addMessage(null, new FacesMessage(SEVERITY_ERROR, e.getMessage(), null)); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters