From: Chad B. <cwb...@us...> - 2008-05-28 16:48:42
|
User: cwbrandon Date: 08/05/28 09:40:46 Modified: andromda-jsf2/src/main/resources/templates/jsf2/forms FormImpl.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/controllers Controller.java.vm Controller.java.vsl Log: Add method for getting max severity of messages stored on the forms, and put a check before the addInfoMessage calls to Not add the info message if the severity is greater than warning Revision Changes Path 1.6 +22 -3 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/forms/FormImpl.java.vsl Index: FormImpl.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/forms/FormImpl.java.vsl,v retrieving revision 1.5 retrieving revision 1.6 diff -u -w -r1.5 -r1.6 --- FormImpl.java.vsl 20 May 2008 02:54:29 -0000 1.5 +++ FormImpl.java.vsl 28 May 2008 16:40:45 -0000 1.6 @@ -151,7 +151,7 @@ * * @return the current Faces messages. */ - public java.util.Collection get${stringUtils.capitalize($formMessagesProperty)}() + public java.util.Collection<javax.faces.application.FacesMessage> get${stringUtils.capitalize($formMessagesProperty)}() { return this.${formMessagesProperty}.values(); } @@ -162,7 +162,7 @@ * * @param messages a collection of the current Faces messages. */ - public void set${stringUtils.capitalize($formMessagesProperty)}(final java.util.Collection messages) + public void set${stringUtils.capitalize($formMessagesProperty)}(final java.util.Collection<javax.faces.application.FacesMessage> messages) { if (messages != null) { @@ -179,12 +179,31 @@ * instances stored within this form. * */ - public void clearJsfMessages() + public void clear${stringUtils.capitalize($formMessagesProperty)}() { this.${formMessagesProperty}.clear(); } /** + * Gets the maximum severity of the messages stored in this form. + * + * @return the maximum severity or null if no messages are present and/or severity isn't set. + */ + public javax.faces.application.FacesMessage.Severity getMaximumMessageSeverity() + { + javax.faces.application.FacesMessage.Severity maxSeverity = null; + for (final javax.faces.application.FacesMessage message : this.get${stringUtils.capitalize($formMessagesProperty)}()) + { + final javax.faces.application.FacesMessage.Severity severity = message.getSeverity(); + if (maxSeverity == null || (severity != null && severity.getOrdinal() > maxSeverity.getOrdinal())) + { + maxSeverity = severity; + } + } + return maxSeverity; + } + + /** * The serial version UID of this class. Needed for serialization. */ private static final long serialVersionUID = ${action.formSerialVersionUID}L; 1.2 +6 -1 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vm Index: Controller.java.vm =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vm,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- Controller.java.vm 5 Dec 2006 19:39:27 -0000 1.1 +++ Controller.java.vm 28 May 2008 16:40:45 -0000 1.2 @@ -24,9 +24,14 @@ #set($messagesFullyQualifiedName = "${managedBeansPackage}.${messagesFullyQualifiedName}") #end #if ($transition.successMessagesPresent) +${indent}final javax.faces.application.FacesMessage.Severity messageSeverity = this.getMaximumMessageSeverity(); +${indent}// - only add info messages if we don't have any messages or warnings are the maximum severity +${indent}if (messageSeverity == null || messageSeverity.equals(javax.faces.application.FacesMessage.SEVERITY_WARN)) +${indent}{ #foreach ($message in $transition.successMessages.entrySet()) ${indent}this.addInfoMessage(${messagesFullyQualifiedName}.get("$message.key", (Object[])null)); #end +${indent}} #end #if ($transition.warningMessagesPresent) #foreach ($message in $transition.warningMessages.entrySet()) 1.16 +26 -0 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.15 retrieving revision 1.16 diff -u -w -r1.15 -r1.16 --- Controller.java.vsl 28 May 2008 15:10:25 -0000 1.15 +++ Controller.java.vsl 28 May 2008 16:40:46 -0000 1.16 @@ -361,6 +361,32 @@ } /** + * Gets the maximum severity of the messages stored in the current form. + * + * @return the maximum message severity. + */ + protected javax.faces.application.FacesMessage.Severity getMaximumMessageSeverity() + { + javax.faces.application.FacesMessage.Severity maximumSeverity = null; + final Object form = this.resolveVariable("form"); + if (form != null) + { + try + { + final java.lang.reflect.Method method = form.getClass().getMethod( + "getMaximumMessageSeverity", + (Class[])null); + maximumSeverity = (javax.faces.application.FacesMessage.Severity)method.invoke(form, (Object[])null); + } + catch (final Exception exception) + { + throw new RuntimeException(exception); + } + } + return maximumSeverity; + } + + /** * Copies all matching properties from the <code>fromForm</code> to the given * <code>toForm</code> overridding any previously set values. */ |
From: Chad B. <cwb...@us...> - 2008-07-21 22:35:50
|
User: cwbrandon Date: 08/07/21 15:35:58 Modified: andromda-jsf2/src/main/resources/templates/jsf2/controllers/crud Controller.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/flow ViewPopulator.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/controllers Controller.java.vm Controller.java.vsl Log: Get rid of exception checking in populator (was causing problems and wasn't needed anyway). Set currentForm as actionForm when message severity is equal to or greater than ERROR. Revision Changes Path 1.17 +19 -31 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.16 retrieving revision 1.17 diff -u -w -r1.16 -r1.17 --- Controller.java.vsl 15 Jul 2008 11:42:44 -0000 1.16 +++ Controller.java.vsl 21 Jul 2008 22:35:56 -0000 1.17 @@ -6,8 +6,6 @@ { 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(); try @@ -32,7 +30,6 @@ } catch (final Throwable throwable) { - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); logger.error(throwable); this.addExceptionMessage(throwable); } @@ -96,7 +93,6 @@ } catch (final Throwable throwable) { - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); logger.error(throwable); this.addExceptionMessage(throwable); } @@ -142,7 +138,6 @@ } catch (final Throwable throwable) { - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); logger.error(throwable); this.addExceptionMessage(throwable); } @@ -178,7 +173,6 @@ } catch (final Throwable throwable) { - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); logger.error(throwable); this.addExceptionMessage(throwable); } @@ -267,7 +261,6 @@ } catch (final Throwable throwable) { - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); logger.error(throwable); this.addExceptionMessage(throwable); } @@ -343,7 +336,6 @@ } catch (final Throwable throwable) { - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); logger.error(throwable); this.addExceptionMessage(throwable); } @@ -375,7 +367,6 @@ } catch (final Throwable throwable) { - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); logger.error(throwable); this.addExceptionMessage(throwable); } @@ -465,7 +456,6 @@ } catch (final Throwable throwable) { - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); logger.error(throwable); this.addExceptionMessage(throwable); } @@ -513,7 +503,6 @@ } catch (final Throwable throwable) { - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); logger.error(throwable); this.addExceptionMessage(throwable); } @@ -524,7 +513,6 @@ try { vos = (java.util.Collection<${manageable.valueObjectClassName}>)${manageable.manageableServiceAccessorCall}.readAll(); } catch (final Throwable throwable) { - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); logger.error(throwable); this.addExceptionMessage(throwable); return null; 1.12 +1 -2 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/ViewPopulator.java.vsl Index: ViewPopulator.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/ViewPopulator.java.vsl,v retrieving revision 1.11 retrieving revision 1.12 diff -u -w -r1.11 -r1.12 --- ViewPopulator.java.vsl 3 Jul 2008 18:27:17 -0000 1.11 +++ ViewPopulator.java.vsl 21 Jul 2008 22:35:58 -0000 1.12 @@ -156,7 +156,6 @@ try { #if (!$view.formActions.empty) - final boolean override = (($jsfUtils.requestClassName)facesContext.getExternalContext().getRequest()).getAttribute(${view.useCase.controller.name}.CONTROLLER_EXCEPTION) != null; // - populate the forms if (form != null) { @@ -166,7 +165,7 @@ facesContext, "$action.formBeanName"); // - populate the $action.formBeanName with any parameters from the previous form - ${managedBeansPackage}.${formPopulatorName}.populateForm(form, $action.formBeanName, override); + ${managedBeansPackage}.${formPopulatorName}.populateForm(form, $action.formBeanName, false); request.setAttribute("$action.formBeanName", $action.formBeanName); #end } 1.3 +1 -2 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vm Index: Controller.java.vm =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- Controller.java.vm 28 May 2008 16:40:45 -0000 1.2 +++ Controller.java.vm 21 Jul 2008 22:35:58 -0000 1.3 @@ -24,9 +24,8 @@ #set($messagesFullyQualifiedName = "${managedBeansPackage}.${messagesFullyQualifiedName}") #end #if ($transition.successMessagesPresent) -${indent}final javax.faces.application.FacesMessage.Severity messageSeverity = this.getMaximumMessageSeverity(); ${indent}// - only add info messages if we don't have any messages or warnings are the maximum severity -${indent}if (messageSeverity == null || messageSeverity.equals(javax.faces.application.FacesMessage.SEVERITY_WARN)) +${indent}else if (messageSeverity == null || messageSeverity.equals(javax.faces.application.FacesMessage.SEVERITY_WARN)) ${indent}{ #foreach ($message in $transition.successMessages.entrySet()) ${indent} this.addInfoMessage(${messagesFullyQualifiedName}.get("$message.key", (Object[])null)); 1.23 +12 -8 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.22 retrieving revision 1.23 diff -u -w -r1.22 -r1.23 --- Controller.java.vsl 17 Jul 2008 18:43:39 -0000 1.22 +++ Controller.java.vsl 21 Jul 2008 22:35:58 -0000 1.23 @@ -10,8 +10,6 @@ { private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(${controller.name}.class); - static final String CONTROLLER_EXCEPTION = ${controller.name}.class.getName() + ".exception"; - #foreach ($operation in $controller.operations) /** $operation.getDocumentation(" * ") @@ -75,6 +73,14 @@ this.setForm("$action.formKey", form, true); #end forward = #processTransition($action) + final javax.faces.application.FacesMessage.Severity messageSeverity = this.getMaximumMessageSeverity(); + if (messageSeverity != null && javax.faces.application.FacesMessage.SEVERITY_ERROR.getOrdinal() <= messageSeverity.getOrdinal()) + { + // - copy any messages to the 'currentForm' + org.apache.commons.beanutils.PropertyUtils.setProperty(currentForm, + "$formMessagesProperty", org.apache.commons.beanutils.PropertyUtils.getProperty(form, "$formMessagesProperty")); + this.setForm("$action.formKey", currentForm, $portlet); + } #saveMessages($action " ") #if (!$action.formFields.empty && $action.formResetRequired) form.reset(); @@ -83,8 +89,7 @@ catch (final Throwable throwable) { logger.error(throwable); - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); - this.setForm("$action.formKey", currentForm, false); + this.setForm("$action.formKey", currentForm, $portlet); final String messageKey = ${managedBeansPackage}.${patternMatchingExceptionHandler}.instance().handleException(throwable); if(org.apache.commons.lang.StringUtils.isEmpty(messageKey)) { @@ -98,8 +103,7 @@ } catch (final Throwable throwable) { - this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable); - this.setForm("$action.formKey", currentForm, false); + this.setForm("$action.formKey", currentForm, $portlet); this.addExceptionMessage(throwable); // - set the forward to null so that we stay on the current view forward = null; @@ -376,7 +380,7 @@ */ protected void setMessagesTitle(final String messagesTitle) { - final Object form = this.resolveVariable("form"); + final Object form = this.resolveVariable("$actionFormKey"); if (form != null) { try @@ -401,7 +405,7 @@ protected javax.faces.application.FacesMessage.Severity getMaximumMessageSeverity() { javax.faces.application.FacesMessage.Severity maximumSeverity = null; - final Object form = this.resolveVariable("form"); + final Object form = this.resolveVariable("$actionFormKey"); if (form != null) { try |