Skip to content

Commit

Permalink
#701 minor improvements to b:message and b:messages (onlyMostSevere
Browse files Browse the repository at this point in the history
… added to b:messages, AJAX compatibility to b:message)
  • Loading branch information
stephanrauh committed Apr 14, 2017
1 parent ab64f67 commit 6bae758
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/main/java/net/bootsfaces/component/message/MessageRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,27 @@ public void encodeBegin(FacesContext context, UIComponent component) throws IOEx
forValue = ExpressionResolver.getComponentIDs(context, message, forValue);

List<FacesMessage> 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");
}
Expand All @@ -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();
Expand Down Expand Up @@ -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";
}
}
17 changes: 17 additions & 0 deletions src/main/java/net/bootsfaces/component/messages/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ protected enum PropertyKeys {
offsetMd,
offsetSm,
offsetXs,
onlyMostSevere,
recursive,
showDetail,
showIcon,
Expand Down Expand Up @@ -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. <P>
* @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. <P>
* 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. <P>
* @return Returns the value of the attribute, or false, if it hasn't been set by the JSF file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ else if (severity.equals(FacesMessage.SEVERITY_FATAL))
List<FacesMessage> severityMessages = messages.get(severity);
if (severityMessages.size() > 0) {
encodeSeverityMessages(facesContext, uiMessages, severity, severityMessages);
if (uiMessages.isOnlyMostSevere()) {
break;
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/meta/META-INF/bootsfaces-b.taglib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13993,6 +13993,18 @@
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[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.]]></description>
<name>only-most-severe</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[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.]]></description>
<name>onlyMostSevere</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[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.]]></description>
<name>recursive</name>
Expand Down
1 change: 1 addition & 0 deletions xtext/BootsFaces.jsfdsl
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<br />" "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."
Expand Down

0 comments on commit 6bae758

Please sign in to comment.