From: Walter M. <wal...@us...> - 2008-07-15 11:43:32
|
User: walterim Date: 08/07/15 04:42:45 Modified: andromda-jsf2/src/main/resources/templates/jsf2/controllers/crud Controller.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/controllers Controller.java.vsl Log: re-throw the exceptions, case there isn't a message to be shown Revision Changes Path 1.16 +63 -21 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/crud/Controller.java.vsl Index: Controller.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/crud/Controller.java.vsl,v retrieving revision 1.15 retrieving revision 1.16 diff -u -w -r1.15 -r1.16 --- Controller.java.vsl 10 Jul 2008 14:59:52 -0000 1.15 +++ Controller.java.vsl 15 Jul 2008 11:42:44 -0000 1.16 @@ -4,6 +4,9 @@ public abstract class ${manageable.controllerName} { + private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(${manageable.controllerName}.class); + + static final String CONTROLLER_EXCEPTION = ${manageable.controllerName}.class.getName() + ".exception"; public String init(){ final ${managedBeansPackage}.AdfFacesContextWrapper contextWrapper = new ${managedBeansPackage}.AdfFacesContextWrapper(); @@ -20,13 +23,17 @@ catch (final Throwable throwable) { final String messageKey = ${managedBeansPackage}.${patternMatchingExceptionHandler}.instance().handleException(throwable); - if(!org.apache.commons.lang.StringUtils.isEmpty(messageKey)) + if(org.apache.commons.lang.StringUtils.isEmpty(messageKey)){ + throw throwable; + } else { this.addErrorMessage(${managedBeansPackage}.Messages.get(messageKey, null)); } } + } catch (final Throwable throwable) { - throwable.printStackTrace(); + this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); + logger.error(throwable); this.addExceptionMessage(throwable); } return "${manageable.viewFullPath}"; @@ -80,13 +87,17 @@ catch (final Throwable throwable) { final String messageKey = ${managedBeansPackage}.${patternMatchingExceptionHandler}.instance().handleException(throwable); - if(!org.apache.commons.lang.StringUtils.isEmpty(messageKey)) + if(org.apache.commons.lang.StringUtils.isEmpty(messageKey)){ + throw throwable; + } else { this.addErrorMessage(${managedBeansPackage}.Messages.get(messageKey, null)); } } + } catch (final Throwable throwable) { - throwable.printStackTrace(); + this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); + logger.error(throwable); this.addExceptionMessage(throwable); } } @@ -122,13 +133,17 @@ catch (final Throwable throwable) { final String messageKey = ${managedBeansPackage}.${patternMatchingExceptionHandler}.instance().handleException(throwable); - if(!org.apache.commons.lang.StringUtils.isEmpty(messageKey)) + if(org.apache.commons.lang.StringUtils.isEmpty(messageKey)){ + throw throwable; + } else { this.addErrorMessage(${managedBeansPackage}.Messages.get(messageKey, null)); } } + } catch (final Throwable throwable) { - throwable.printStackTrace(); + this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); + logger.error(throwable); this.addExceptionMessage(throwable); } return null; @@ -154,13 +169,17 @@ catch (final Throwable throwable) { final String messageKey = ${managedBeansPackage}.${patternMatchingExceptionHandler}.instance().handleException(throwable); - if(!org.apache.commons.lang.StringUtils.isEmpty(messageKey)) + if(org.apache.commons.lang.StringUtils.isEmpty(messageKey)){ + throw throwable; + } else { this.addErrorMessage(${managedBeansPackage}.Messages.get(messageKey, null)); } } + } catch (final Throwable throwable) { - throwable.printStackTrace(); + this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); + logger.error(throwable); this.addExceptionMessage(throwable); } @@ -239,13 +258,17 @@ catch (final Throwable throwable) { final String messageKey = ${managedBeansPackage}.${patternMatchingExceptionHandler}.instance().handleException(throwable); - if(!org.apache.commons.lang.StringUtils.isEmpty(messageKey)) + if(org.apache.commons.lang.StringUtils.isEmpty(messageKey)){ + throw throwable; + } else { this.addErrorMessage(${managedBeansPackage}.Messages.get(messageKey, null)); } } + } catch (final Throwable throwable) { - throwable.printStackTrace(); + this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); + logger.error(throwable); this.addExceptionMessage(throwable); } return null; @@ -311,13 +334,17 @@ catch (final Throwable throwable) { final String messageKey = ${managedBeansPackage}.${patternMatchingExceptionHandler}.instance().handleException(throwable); - if(!org.apache.commons.lang.StringUtils.isEmpty(messageKey)) + if(org.apache.commons.lang.StringUtils.isEmpty(messageKey)){ + throw throwable; + } else { this.addErrorMessage(${managedBeansPackage}.Messages.get(messageKey, null)); } } + } catch (final Throwable throwable) { - throwable.printStackTrace(); + this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); + logger.error(throwable); this.addExceptionMessage(throwable); } return null; @@ -339,13 +366,17 @@ catch (final Throwable throwable) { final String messageKey = ${managedBeansPackage}.${patternMatchingExceptionHandler}.instance().handleException(throwable); - if(!org.apache.commons.lang.StringUtils.isEmpty(messageKey)) + if(org.apache.commons.lang.StringUtils.isEmpty(messageKey)){ + throw throwable; + } else { this.addErrorMessage(${managedBeansPackage}.Messages.get(messageKey, null)); } } + } catch (final Throwable throwable) { - throwable.printStackTrace(); + this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); + logger.error(throwable); this.addExceptionMessage(throwable); } return null; @@ -425,19 +456,23 @@ catch (final Throwable throwable) { final String messageKey = ${managedBeansPackage}.${patternMatchingExceptionHandler}.instance().handleException(throwable); - if(!org.apache.commons.lang.StringUtils.isEmpty(messageKey)) + if(org.apache.commons.lang.StringUtils.isEmpty(messageKey)){ + throw throwable; + } else { this.addErrorMessage(${managedBeansPackage}.Messages.get(messageKey, null)); } } + } catch (final Throwable throwable) { - throwable.printStackTrace(); + this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); + logger.error(throwable); this.addExceptionMessage(throwable); } } public void doDelete(${idParamClass} ${manageable.manageableIdentifier.name}, ${manageable.formBeanType} form) throws Exception { - ${manageable.manageableServiceAccessorCall}.delete(new Long[]{${manageable.manageableIdentifier.name}}); + ${manageable.manageableServiceAccessorCall}.delete(new ${idParamClass}[]{${manageable.manageableIdentifier.name}}); doSearch(form); } @@ -478,7 +513,8 @@ } catch (final Throwable throwable) { - throwable.printStackTrace(); + this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); + logger.error(throwable); this.addExceptionMessage(throwable); } } @@ -487,9 +523,10 @@ final java.util.Collection<${manageable.valueObjectClassName}> vos; try { vos = (java.util.Collection<${manageable.valueObjectClassName}>)${manageable.manageableServiceAccessorCall}.readAll(); - } catch (Exception e) { - e.printStackTrace(); - this.addExceptionMessage(e); + } catch (final Throwable throwable) { + this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); + logger.error(throwable); + this.addExceptionMessage(throwable); return null; } final java.util.Collection<javax.faces.model.SelectItem> result=new java.util.ArrayList<javax.faces.model.SelectItem>(vos.size()); @@ -669,6 +706,11 @@ } } + protected void setRequestAttribute(final String name, final Object object) + { + ${managedBeansPackage}.JsfUtils.setAttribute(this.getContext().getExternalContext().getRequest(), name, object); + } + // crud-controller merge-point } \ No newline at end of file 1.21 +4 -1 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vsl Index: Controller.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vsl,v retrieving revision 1.20 retrieving revision 1.21 diff -u -w -r1.20 -r1.21 --- Controller.java.vsl 3 Jul 2008 18:27:18 -0000 1.20 +++ Controller.java.vsl 15 Jul 2008 11:42:44 -0000 1.21 @@ -86,10 +86,13 @@ this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); this.setForm("$action.formKey", currentForm, false); final String messageKey = ${managedBeansPackage}.${patternMatchingExceptionHandler}.instance().handleException(throwable); - if(!org.apache.commons.lang.StringUtils.isEmpty(messageKey)) + if(org.apache.commons.lang.StringUtils.isEmpty(messageKey)){ + throw throwable; + } else { this.addErrorMessage(${managedBeansPackage}.Messages.get(messageKey, null)); } } + } catch (final Throwable throwable) { this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); |