public class BaseErrorHandler extends Object implements IErrorHandler
Modifier and Type | Field and Description |
---|---|
protected String |
action |
static String |
ACTION_NONE
Do not handle error, but just parse it.
|
static String |
ACTION_REDIRECT
Client browser is redirected to custom error handling page.
|
static String |
ACTION_REPORT_DETAILS
Reports error details only
|
static String |
ACTION_REPORT_SUMMARY
Default handler behavior is to report error summary only
|
static String |
ACTION_REPORT_SUMMARY_DETAILS
Reports error summary and details details only
|
protected IErrorHandler |
chainHandler |
protected String |
details |
protected String |
errorPage |
protected Exception |
exception |
protected String |
parsedDetails |
protected String |
parsedSummary |
protected String |
severity |
static String |
SEVERITY_ERROR |
static String |
SEVERITY_FATAL |
static String |
SEVERITY_INFO |
static String |
SEVERITY_WARN |
protected Object |
source |
protected String |
summary |
protected String |
viewID |
Constructor and Description |
---|
BaseErrorHandler()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected static String |
formatMessage(String message,
String parsedMessage)
Helper method to format the Exception's error messages with a custom message.
|
String |
getAction()
How error should be handled.
|
IErrorHandler |
getChainHandler()
Returns chained error handler.
|
String |
getDetails()
Returns error details message as parsed from service exception or configured.
|
String |
getErrorPage()
Error page name when error handling action is set to
ACTION_REDIRECT |
Exception |
getException()
Returns the last error.
|
protected FacesMessage.Severity |
getFacesSeverity()
Return the current severity on this handler as a FacesMessage.
|
String |
getSeverity()
Returns message severity if message is reported through Faces Messages control on the page.
|
Object |
getSource()
Returns source object (service bean) for the last error.
|
String |
getSummary()
Returns error message summary as parsed from Exception or configured directly.
|
protected void |
gotoPage(String page,
boolean redirect)
Switches to the specified view page.
|
protected void |
handleError()
Handle the error based on the action set on this handler.
|
boolean |
handleError(Object source,
Exception error)
Handles service error based on the action set on this handler.
|
boolean |
isHasError()
Returns true if there was error handled by this handler instance.
|
protected boolean |
parseError()
Set the Summary and Details from the exception's cause.
|
void |
reset()
Reset state of the error handler.
|
void |
returnBack()
Redirects the page back to the original page, after showing error reporting page when
error handler action is set to
ACTION_REDIRECT |
void |
setAction(String action)
Sets error handling action
|
void |
setChainHandler(IErrorHandler handler)
Sets chained error handler to delegate error handling to, if this handler fails to handle it.
|
void |
setDetails(String details)
Overrides error details message with custom value
Set a custom message with formating to include the raw error message from the exception.
|
void |
setErrorPage(String errorPage)
Sets error page to redirect to when error happens and error handling action is set to
ACTION_REDIRECT . |
void |
setSeverity(String severity)
Sets message severity is message is reported through Faces Messages control on the page.
|
void |
setSummary(String summary)
Overrides error message summary with custom value.
|
public static final String SEVERITY_INFO
public static final String SEVERITY_WARN
public static final String SEVERITY_ERROR
public static final String SEVERITY_FATAL
public static final String ACTION_NONE
public static final String ACTION_REPORT_SUMMARY
public static final String ACTION_REPORT_DETAILS
public static final String ACTION_REPORT_SUMMARY_DETAILS
public static final String ACTION_REDIRECT
protected Object source
protected Exception exception
protected String parsedSummary
protected String parsedDetails
protected String summary
protected String details
protected String severity
protected String action
protected String errorPage
protected IErrorHandler chainHandler
protected String viewID
public BaseErrorHandler()
reset()
.public Object getSource()
getSource
in interface IErrorHandler
public Exception getException()
getException
in interface IErrorHandler
public String getDetails()
public void setDetails(String details)
MessageFormat.format( String, Object[])
details
- A custom error message.public String getSeverity()
SEVERITY_INFO
, SEVERITY_WARN
,
SEVERITY_ERROR
, or SEVERITY_FATAL
.public void setSeverity(String severity)
severity
- The message severity, use SEVERITY_INFO
, SEVERITY_WARN
,
SEVERITY_ERROR
, or SEVERITY_FATAL
.public String getSummary()
public void setSummary(String summary)
summary
- A preset summary for this error handler.public String getAction()
public void setAction(String action)
action
- One of the Available actions: ACTION_NONE
, ACTION_REPORT_SUMMARY
,
ACTION_REPORT_DETAILS
, ACTION_REPORT_SUMMARY_DETAILS
and ACTION_REDIRECT
.public String getErrorPage()
ACTION_REDIRECT
public void setErrorPage(String errorPage)
ACTION_REDIRECT
.errorPage
- The URI of the page, for example: /portlet1/mypage.viewpublic IErrorHandler getChainHandler()
public void setChainHandler(IErrorHandler handler)
handler
- The to delegate error handling to.public boolean handleError(Object source, Exception error) throws Exception
handleError
in interface IErrorHandler
source
- The source object that threw the exception.error
- The Exception to handle.Exception
public boolean isHasError()
public void reset()
reset
in interface IErrorHandler
public void returnBack()
ACTION_REDIRECT
protected boolean parseError()
Throwable.getCause()
protected void handleError() throws Exception
ACTION_NONE
, ACTION_REPORT_SUMMARY
,
ACTION_REPORT_DETAILS
, ACTION_REPORT_SUMMARY_DETAILS
and ACTION_REDIRECT
.Exception
protected FacesMessage.Severity getFacesSeverity()
FacesMessage.SEVERITY_ERROR
.protected void gotoPage(String page, boolean redirect)
page
- The URI of the page, for example: /portlet1/mypage.viewredirect
- True to redirect to the page, false to just change the FacesContext view root.protected static String formatMessage(String message, String parsedMessage)
message
- The custom message format. See MessageFormat.format(String, Object[])parsedMessage
- The Exception message.