Tuesday 5 March 2013

How to Customizing Error Handling?

You can report errors using a custom error handler that extends the default DCErrorHandlerImpl class. You are not required to write any code to register your custom exception handler class. Instead, you select the root node of the DataBindings.cpx file in the Structure window, and then use the Property Inspector to set the ErrorHandlerClass property to the fully qualified name of the error handler you want it to use.

Your custom error handler can contain the following overridable methods:
reportException(): Called to report any exception that occurs. It can be overridden to analyze reported exceptions.
getDisplayMessage(): Returns the message that will be reported to JSF for each error that occurs. Returning null is the way your custom error handler signals that a given exception should not be reported to the client.
getDetailedDisplayMessage(): Returns the detail portion of the message as a String object or HTML that will be reported to JSF for each error that occurs. Returning null is the way your custom error handler signals that a given exception should not be reported to the client.
skipException(): Returns a boolean depending on whether you want to display each item from the nested exception in the final error list displayed to the user. This method override lets you implement logic to check for specifics exception types and, based on the business scenario, determine whether to display it in the list.

custom error handler that extends the DCErrorHandlerImpl class and shows the override for the skipException() method that is needed to skip exceptions that should not appear in the list displayed to the user.
Example: 
Custom Error Handlerpackage view.controller.fwkext;
 import java.sql.SQLIntegrityConstraintViolationException; 
 import java.util.ArrayList; import java.util.List;
 import oracle.adf.model.binding.DCBindingContainer; 
 import oracle.adf.model.binding.DCErrorHandlerImpl; 
 import oracle.jbo.CSMessageBundle; import oracle.jbo.DMLConstraintException; import oracle.jbo.JboException;
 public class CustomErrorHandler extends DCErrorHandlerImpl { List<ExceptionMapper> exceptionMapperList = new ArrayList<ExceptionMapper>();
 public CustomErrorHandler() { this(true);
 }
 public CustomErrorHandler(boolean setToThrow) 
{
 super(setToThrow); exceptionMapperList.add(new DisableJboExceptionCodesMapper());
 }
 public void reportException(DCBindingContainer bc, Exception ex)
 {
 for (ExceptionMapper mapper : exceptionMapperList)
 { 
if (mapper.canMapException(ex))
 {
 ex = mapper.mapException(ex); 
 }
 }
 super.reportException(bc, ex); 
 }
 /** * If an exception is a RowValException or a TxnValException and they * have nested exceptions, then do not display it. This example shows * an implementation that skips the SQLIntegrityConstraintViolationException * from displaying in the error final list displayed to the user. */ 
@Override protected boolean skipException(Exception ex) {
 if (ex instanceof DMLConstraintException) 
{
 return false;
 }
 else if (ex instanceof SQLIntegrityConstraintViolationException) 
 return true; 
 } 
 return super.skipException(ex);
 }
 }

No comments:

Post a Comment