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. */ |