To override the default error handler one can extend the DCErrorHandlerImpl. In this you can process the exceptions or can choose to suppress them. In this post i will explain a way to suppress the RowValException message and display only the detail entity attribute level exception ie AttrValException. In ADF the exceptions are grouped and raised together as a single object. For example let's say that 2 of the attributes fail the mandatory validation then the exceptions raised for them will be 2 individual AttrValException these are then attached as detail objects into a RowValException and if there are many such RowValException they will be attached and raised together as a TxnValException. So now to handle the aforementioned task we need to recursively process the exceptions and suppress the RowValException message. The snippet below shows that :-
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | public class MyErrorHandler extends DCErrorHandlerImpl { private static final ADFLogger logger = ADFLogger.createADFLogger(VleAdminErrorHandler.class); private static ResourceBundle rb = ResourceBundle.getBundle("mypackage.myBundle"); public MyErrorHandler() { super(true); } public MyErrorHandler(boolean setToThrow) { super(setToThrow); } public void reportException(DCBindingContainer bc, java.lang.Exception ex) { disableAppendCodes(ex); logger.info("entering reportException() method"); BindingContext ctx = bc.getBindingContext(); String err_code; err_code = null; if(ex instanceof NullPointerException){ logger.severe(ex); JboException e = new JboException(rb.getString("STANDARD_ERROR_MESSAGE")); super.reportException(bc, e); } else if(ex instanceof RowValException){ Object[] exceptions= ((RowValException)ex).getDetails(); if(exceptions!=null){ for(int i=0;i<exceptions.length;i++){ if(exceptions[i] instanceof RowValException){ this.reportException(bc, (Exception)exceptions[i]); } else if(exceptions[i] instanceof AttrValException){ super.reportException(bc, (Exception)exceptions[i]); } } } else{ this.reportException(bc, ex); } } else if (ex instanceof TxnValException) { Object[] exceptions= ((TxnValException)ex).getDetails(); if(exceptions!=null){ for(int i=0;i<exceptions.length;i++){ if(exceptions[i] instanceof RowValException){ this.reportException(bc, (Exception)exceptions[i]); } else{ super.reportException(bc, (Exception)exceptions[i]); } } } else { super.reportException(bc, ex); } } else if (ex instanceof oracle.jbo.DMLException) { JboException e = new JboException(rb.getString("STANDARD_ERROR_MESSAGE")); super.reportException(bc, e); } else if(ex instanceof javax.xml.ws.WebServiceException){ JboException e=new JboException(rb.getString("WEB_SERVICE_EXCEPTION")); super.reportException(bc, e); } else if (ex instanceof JboException) { super.reportException(bc, ex); } } public static FacesMessage getMessageFromBundle(String key, FacesMessage.Severity severity) { ResourceBundle bundle = ResourceBundle.getBundle("sahaj.apps.vleadministration.view.resources.VLEAdministrationUIBundle"); String summary = JSFUtil.getStringSafely(bundle, key, null); String detail = JSFUtil.getStringSafely(bundle, key + "_detail", summary); FacesMessage message = new FacesMessage(summary, detail); message.setSeverity(severity); return message; } 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]); } } } } @Override protected boolean skipException(Exception ex) { if (ex instanceof JboException) { return false; } else if (ex instanceof SQLIntegrityConstraintViolationException) { return true; } return super.skipException(ex); } @Override public String getDisplayMessage(BindingContext bindingContext, Exception exception) { return super.getDisplayMessage(bindingContext, exception); } @Override public DCErrorMessage getDetailedDisplayMessage(BindingContext bindingContext, RegionBinding regionBinding, Exception exception) { return super.getDetailedDisplayMessage(bindingContext, regionBinding, exception); } } |
In this snippet i am recursively processing TxnValException->RowValException -> AttrValException. The AttrValException is being passed in the super call to the DCErrorHandlerImpl to process and display the message.