Dive into Oracle ADF

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 9:16:17 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Search blog with Google:
 

Search BC4J JavaDoc:
 

March 2005
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Feb   Apr

Get Firefox!

Friday, March 11, 2005

Several people have written in over the last several months asking whether in Oracle ADF there is a central "chokepoint" that you can override when exceptions are thrown. The answer is yes.

If you register a custom implementation of the oracle.adf.model.binding.DCErrorHandler interface, then you can be in control of how each exception is thrown.  The ADFBindingFilter registers and instance of DCErrorHandlerImpl as a base implementation. You can subclass oracle.adf.model.binding.DCErrorHandlerImpl as a quick way to implement the interface.

You register a custom implementation by calling setErrorHandler() on oracle.adf.model.binding.BindingContext object. For a Struts-based web application, to register a custom handler you can override DataAction.handleLifecycle() and call DataActionContext.getBindingContext().setErrorHandler() before calling super.handleLifecycle().

For example, here is the custom error handler that I've added to the 10.1.2 version of the ADF Toy Store Demo which calls setAppendCodes(false) on every JboException that is thrown so that error messages don't end up with the JBO-XXXXX codes in the message displayed to the user. Remember that in the bundled exception handling mode (which is the default for ADF web apps) a single exception will be thrown that contains a nested list of detail exceptions. Those, in turn, might contain other nested detail exceptions, forming a tree of exception objects.

    package toystore.fwk.controller;
    import oracle.adf.model.binding.DCBindingContainer;
    import oracle.adf.model.binding.DCErrorHandlerImpl;
    import oracle.jbo.JboException;
    /**
     * Custom ADF Binding Layer Error Handler
     *
     * This class is "installed" as the error handler implementation by
     * the ToyStoreDataForwardAction's handleLifecycle() method.
     */
    public class ToyStoreErrorHandler extends DCErrorHandlerImpl {
      /**
       * Constructor for custom error handler.
       *
       * @param setToThrow should exceptions throw or not
       */
      public ToyStoreErrorHandler(boolean setToThrow) {
        super(setToThrow);
      }
      /**
       * Overridden ADF binding framework method to customize the way
       * that Exceptions are reported to the client.
       *
       * Here we set the "append codes" flag to false on each JboException
       * in the exception (and any detail JboExceptions it contains)
       *
       * @param bc BindingContainer
       * @param ex exception being reported
       */
      public void reportException(DCBindingContainer bc, Exception ex) {
        /*
         * Force JboException's reported to the binding layer to avoid
         * printing out the JBO-XXXXX product prefix and code.
         */
        disableAppendCodes(ex);
        super.reportException(bc, ex);
      }
      private void disableAppendCodes(Exception ex) {
        if (ex instanceof JboException) {
          JboException jboEx = (JboException) ex;
          jboEx.setAppendCodes(false);
          Object[] detailExceptions = jboEx.getDetails();
          if ((detailExceptions != null) && (detailExceptions.length > 0)) {
            for (int z = 0, numEx = detailExceptions.length; z < numEx; z++) {
              disableAppendCodes((Exception) detailExceptions[z]);
            }
          }
        }
      }
    }

11:44:23 PM    



© Copyright 2008 Steve Muench.