diff --git a/src/main/java/net/bootsfaces/component/message/MessageRenderer.java b/src/main/java/net/bootsfaces/component/message/MessageRenderer.java index 01830717f..e8a68dd77 100644 --- a/src/main/java/net/bootsfaces/component/message/MessageRenderer.java +++ b/src/main/java/net/bootsfaces/component/message/MessageRenderer.java @@ -60,22 +60,27 @@ public void encodeBegin(FacesContext context, UIComponent component) throws IOEx forValue = ExpressionResolver.getComponentIDs(context, message, forValue); List messageList = context.getMessageList(forValue); - + ResponseWriter rw = context.getResponseWriter(); int numberOfDivs = 0; - + boolean idHasBeenRendered = false; + String responsiveStyleClass = Responsive.getResponsiveStyleClass(message, false).trim(); + String clientId = message.getClientId(context); if (!responsiveStyleClass.isEmpty()) { numberOfDivs++; rw.startElement("div", component); writeAttribute(rw, "class", responsiveStyleClass); + writeAttribute(rw, "id", clientId); + idHasBeenRendered = true; } - + if (!messageList.isEmpty()) { - String clientId = message.getClientId(context); numberOfDivs++; rw.startElement("div", message); - writeAttribute(rw, "id", clientId); + if (!idHasBeenRendered) { + writeAttribute(rw, "id", clientId); + } if (null != message.getDir()) { rw.writeAttribute("dir", message.getDir(), "dir"); } @@ -97,12 +102,12 @@ public void encodeBegin(FacesContext context, UIComponent component) throws IOEx else if (!style.endsWith(";")) style += ";"; String severityStyle = findHighestSeverityStyle(messageList, message); - if (null==severityStyle) - severityStyle=""; + if (null == severityStyle) + severityStyle = ""; else if (!severityStyle.endsWith(";")) - severityStyle+=";"; + severityStyle += ";"; - writeAttribute(rw, "style", style+severityStyle); + writeAttribute(rw, "style", style + severityStyle); writeAttribute(rw, "role", "alert"); boolean onlyMostSevere = message.isOnlyMostSevere(); @@ -248,11 +253,12 @@ else if (severity.equals(FacesMessage.SEVERITY_FATAL)) hasFatal = true; } if (hasFatal) - return "bficon bficon-error-circle-o";//"fa fa-exclamation-circle"; + return "bficon bficon-error-circle-o";// "fa fa-exclamation-circle"; if (hasError) - return "bficon bficon-error-circle-o";//"fa fa-exclamation-circle"; + return "bficon bficon-error-circle-o";// "fa fa-exclamation-circle"; if (hasWarning) - return "bficon bficon-warning-triangle-o";//"fa fa-exclamation-triangle"; - return "bficon bficon-info";//"fa fa-info-circle"; + return "bficon bficon-warning-triangle-o";// "fa + // fa-exclamation-triangle"; + return "bficon bficon-info";// "fa fa-info-circle"; } } diff --git a/src/main/java/net/bootsfaces/component/messages/Messages.java b/src/main/java/net/bootsfaces/component/messages/Messages.java index e103cdddb..6c6d6a538 100644 --- a/src/main/java/net/bootsfaces/component/messages/Messages.java +++ b/src/main/java/net/bootsfaces/component/messages/Messages.java @@ -77,6 +77,7 @@ protected enum PropertyKeys { offsetMd, offsetSm, offsetXs, + onlyMostSevere, recursive, showDetail, showIcon, @@ -509,6 +510,22 @@ public void setOffsetXs(String _offsetXs) { getStateHelper().put(PropertyKeys.offsetXs, _offsetXs); } + /** + * By default, b:messages shows every message reported. You can limit it to the most important messages by setting this flag to true. In this case, BootsFaces shows only the message with the severity level.

+ * @return Returns the value of the attribute, or false, if it hasn't been set by the JSF file. + */ + public boolean isOnlyMostSevere() { + return (boolean) (Boolean) getStateHelper().eval(PropertyKeys.onlyMostSevere, false); + } + + /** + * By default, b:messages shows every message reported. You can limit it to the most important messages by setting this flag to true. In this case, BootsFaces shows only the message with the severity level.

+ * Usually this method is called internally by the JSF engine. + */ + public void setOnlyMostSevere(boolean _onlyMostSevere) { + getStateHelper().put(PropertyKeys.onlyMostSevere, _onlyMostSevere); + } + /** * If set to true, b:messages checks the for attributes using a slower algorithm that doesn't require you to put the component into a namingcontainer.

* @return Returns the value of the attribute, or false, if it hasn't been set by the JSF file. diff --git a/src/main/java/net/bootsfaces/component/messages/MessagesRenderer.java b/src/main/java/net/bootsfaces/component/messages/MessagesRenderer.java index f7af8f92e..cd9bd5974 100644 --- a/src/main/java/net/bootsfaces/component/messages/MessagesRenderer.java +++ b/src/main/java/net/bootsfaces/component/messages/MessagesRenderer.java @@ -136,6 +136,9 @@ else if (severity.equals(FacesMessage.SEVERITY_FATAL)) List severityMessages = messages.get(severity); if (severityMessages.size() > 0) { encodeSeverityMessages(facesContext, uiMessages, severity, severityMessages); + if (uiMessages.isOnlyMostSevere()) { + break; + } } } diff --git a/src/main/meta/META-INF/bootsfaces-b.taglib.xml b/src/main/meta/META-INF/bootsfaces-b.taglib.xml index e1da993d6..3ff5baa1d 100644 --- a/src/main/meta/META-INF/bootsfaces-b.taglib.xml +++ b/src/main/meta/META-INF/bootsfaces-b.taglib.xml @@ -13993,6 +13993,18 @@ false java.lang.String + + + only-most-severe + false + java.lang.Boolean + + + + onlyMostSevere + false + java.lang.Boolean + recursive diff --git a/xtext/BootsFaces.jsfdsl b/xtext/BootsFaces.jsfdsl index 4260ec458..86de60714 100644 --- a/xtext/BootsFaces.jsfdsl +++ b/xtext/BootsFaces.jsfdsl @@ -1278,6 +1278,7 @@ widget messages info-style "CSS style to be used for messages with severity \"INFO\"." line-break Boolean default "true" "If there's more than one message, they can optionally be separated by a line break. By default, the separator is a br tag." line-break-tag String default "
" "If there's more than one message, they can optionally be separated by a line break. By default, the separator is a br tag. You can replace if with an arbitrary HTML snippet." + only-most-severe Boolean default "false" "By default, b:messages shows every message reported. You can limit it to the most important messages by setting this flag to true. In this case, BootsFaces shows only the message with the severity level." rendered Boolean inherited "A boolean value that indicates whether this component should be rendered. Default value: true." redisplay Boolean inherited "Set the flag indicating whether messages that have already been displayed should be displayed again. By default, messages are always redisplayed. Most likely, you'll want to set this flag to false." recursive Boolean default "false" "If set to true, b:messages checks the for attributes using a slower algorithm that doesn't require you to put the component into a namingcontainer."