Author: abelevich
Date: 2007-10-29 05:34:07 -0400 (Mon, 29 Oct 2007)
New Revision: 3588
Modified:
branches/3.1.x/ui/message/src/main/config/component/message.xml
branches/3.1.x/ui/message/src/main/java/org/richfaces/component/UIRichMessage.java
branches/3.1.x/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/RichMessageBaseRenderer.java
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessageRenderer.java
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessagesRenderer.java
Log:
add level attribute to show only certain category of messages RF-1059
Modified: branches/3.1.x/ui/message/src/main/config/component/message.xml
===================================================================
--- branches/3.1.x/ui/message/src/main/config/component/message.xml 2007-10-29 09:18:31
UTC (rev 3587)
+++ branches/3.1.x/ui/message/src/main/config/component/message.xml 2007-10-29 09:34:07
UTC (rev 3588)
@@ -36,6 +36,14 @@
</test>
</tag>
+ <property>
+ <name>level</name>
+ <classname>java.lang.String</classname>
+ <defaultvalue>"ALL"</defaultvalue>
+ <description>
+ comma-separated list of messages categoris which should be displayed
+ </description>
+ </property>
<property attachedstate="true">
<name>passedLabel</name>
@@ -292,7 +300,16 @@
Attribute should define the label to be displayed when no message appears
</description>
</property>
+ <property>
+ <name>level</name>
+ <classname>java.lang.String</classname>
+ <description>
+ comma-separated list of messages categoris which should be displayed
+ </description>
+ <defaultvalue>"ALL"</defaultvalue>
+ </property>
+
<property>
<name>var</name>
<classname>java.lang.String</classname>
Modified:
branches/3.1.x/ui/message/src/main/java/org/richfaces/component/UIRichMessage.java
===================================================================
---
branches/3.1.x/ui/message/src/main/java/org/richfaces/component/UIRichMessage.java 2007-10-29
09:18:31 UTC (rev 3587)
+++
branches/3.1.x/ui/message/src/main/java/org/richfaces/component/UIRichMessage.java 2007-10-29
09:34:07 UTC (rev 3588)
@@ -44,4 +44,9 @@
isPassed = false;
}
+ public abstract String getLevel();
+
+ public abstract void setLevel(String level);
+
+
}
\ No newline at end of file
Modified:
branches/3.1.x/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java
===================================================================
---
branches/3.1.x/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java 2007-10-29
09:18:31 UTC (rev 3587)
+++
branches/3.1.x/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java 2007-10-29
09:34:07 UTC (rev 3588)
@@ -16,8 +16,7 @@
private boolean isPassed = false;
-
-
+
public boolean isPassed(){
return isPassed;
}
@@ -36,5 +35,9 @@
isPassed = true;
super.decode(context);
}
-
+
+ public abstract String getLevel();
+
+ public abstract void setLevel(String level);
+
}
Modified:
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/RichMessageBaseRenderer.java
===================================================================
---
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/RichMessageBaseRenderer.java 2007-10-29
09:18:31 UTC (rev 3587)
+++
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/RichMessageBaseRenderer.java 2007-10-29
09:34:07 UTC (rev 3588)
@@ -1,17 +1,22 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIMessage;
+import javax.faces.component.UIMessages;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.resource.InternetResource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -30,7 +35,62 @@
public static final String COMPONENT_NOT_FOUND_IN_VIEW_WARN_MESSAGE = "component
not found in the view WARNING";
+ private static final String ERROR_NAME = "ERROR";
+ private static final String WARN_NAME = "WARN";
+
+ private static final String FATAL_NAME = "FATAL";
+
+ private static final String INFO_NAME = "INFO";
+
+ private static final String ALL_NAME = "ALL";
+
+ protected List acceptLevels = new ArrayList();
+
+
+ private final InternetResource[] styles =
{getResource("/org/richfaces/renderkit/html/css/msg.css"),getResource("/org/richfaces/renderkit/html/css/msgs.css")};
+
+ private InternetResource[] stylesAll = null;
+
+
+ protected InternetResource[] getStyles(){
+ synchronized (this){
+ if(stylesAll == null){
+
+ InternetResource[] rsrcs = super.getStyles();
+ boolean ignoreSuper = rsrcs == null || rsrcs.length == 0;
+ boolean ignoreThis = styles == null || styles.length == 0;
+
+ if(ignoreSuper){
+
+ if (ignoreThis) {
+ stylesAll = new InternetResource[0];
+ } else {
+ stylesAll = styles;
+ }
+
+ }else{
+
+ if(ignoreThis){
+ stylesAll = rsrcs;
+ }else{
+ Set rsrcsSet = new java.util.LinkedHashSet();
+ for(int i = 0; i < rsrcs.length; i++ ){
+ rsrcsSet.add(rsrcs[i]);
+ }
+
+ for(int i = 0; i < styles.length; i++ ){
+ rsrcsSet.add(styles[i]);
+ }
+ stylesAll = (InternetResource[]) rsrcsSet.toArray(new
InternetResource[rsrcsSet.size()]);
+ }
+ }
+ }
+ }
+
+ return stylesAll;
+ }
+
protected Iterator getMessageIterator(FacesContext context, String forClientId,
UIComponent component) throws IOException{
Iterator msgIter = null;
@@ -264,6 +324,49 @@
return retComp;
};
+ protected boolean isAcceptableMessage(FacesMessage message){
+
+ boolean accept = false;
+
+ if(acceptLevels.contains(ALL_NAME)){
+ return true;
+ }
+
+ Severity severity = message.getSeverity();
+
+ if(severity == FacesMessage.SEVERITY_ERROR
+ && acceptLevels.contains(ERROR_NAME)){
+ accept = true;
+
+ }else if(severity == FacesMessage.SEVERITY_FATAL
+ && acceptLevels.contains(FATAL_NAME)){
+ accept = true;
+
+ }else if(severity == FacesMessage.SEVERITY_INFO
+ && acceptLevels.contains(INFO_NAME)){
+ accept = true;
+
+ }else if(severity == FacesMessage.SEVERITY_WARN
+ && acceptLevels.contains(WARN_NAME)){
+ accept = true;
+ }
+
+ return accept;
+ }
+
+ protected List creatAcceptLevels(String [] levels){
+
+ List acceptLevels = new ArrayList();
+
+ for (int i = 0; i < levels.length; i++) {
+ acceptLevels.add(levels[i].toUpperCase());
+ }
+
+ return acceptLevels;
+ }
+
+
+
public abstract void renderMarkerHtml(UIComponent component, UIComponent markerFacet,
FacesContext context, ResponseWriter writer,
String markerClass, String markerStyle) throws IOException;
Modified:
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessageRenderer.java
===================================================================
---
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessageRenderer.java 2007-10-29
09:18:31 UTC (rev 3587)
+++
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessageRenderer.java 2007-10-29
09:34:07 UTC (rev 3588)
@@ -2,7 +2,6 @@
import java.io.IOException;
import java.util.Iterator;
-import java.util.Set;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
@@ -11,7 +10,6 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.ajax4jsf.resource.InternetResource;
import org.richfaces.component.UIRichMessage;
import org.richfaces.renderkit.RichMessageBaseRenderer;
@@ -22,51 +20,7 @@
*/
public class HtmlRichMessageRenderer extends RichMessageBaseRenderer{
- private final InternetResource[] styles =
{getResource("/org/richfaces/renderkit/html/css/msg.css")};
- private InternetResource[] stylesAll = null;
-
-
- protected InternetResource[] getStyles(){
- synchronized (this){
- if(stylesAll == null){
-
- InternetResource[] rsrcs = super.getStyles();
- boolean ignoreSuper = rsrcs == null || rsrcs.length == 0;
- boolean ignoreThis = styles == null || styles.length == 0;
-
- if(ignoreSuper){
-
- if (ignoreThis) {
- stylesAll = new InternetResource[0];
- } else {
- stylesAll = styles;
- }
-
- }else{
- if(ignoreThis){
- stylesAll = rsrcs;
- }else{
- Set rsrcsSet = new java.util.LinkedHashSet();
-
- for(int i = 0; i < rsrcs.length; i++ ){
- rsrcsSet.add(rsrcs[i]);
- }
-
- for(int i = 0; i < styles.length; i++ ){
- rsrcsSet.add(styles[i]);
- }
-
- stylesAll = (InternetResource[]) rsrcsSet.toArray(new
InternetResource[rsrcsSet.size()]);
- }
- }
- }
- }
-
- return stylesAll;
- }
-
-
protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
Iterator msgIter = null;
@@ -105,11 +59,12 @@
ResponseWriter writer = context.getResponseWriter();
- outerStyles(uiMsg, context, writer, facesMsg);
- renderMarkerFacet(uiMsg,context, writer,facesMsg);
- renderLabel(uiMsg, context, writer, facesMsg);
-
-
+ acceptLevels = creatAcceptLevels(uiMsg.getLevel().split(","));
+ if(isAcceptableMessage(facesMsg)){
+ outerStyles(uiMsg, context, writer, facesMsg);
+ renderMarkerFacet(uiMsg,context, writer,facesMsg);
+ renderLabel(uiMsg, context, writer, facesMsg);
+ }
}
public void renderOuterStyles(UIComponent component, FacesContext context,
ResponseWriter writer,String outerStyle, String outerClass) throws IOException{
Modified:
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessagesRenderer.java
===================================================================
---
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessagesRenderer.java 2007-10-29
09:18:31 UTC (rev 3587)
+++
branches/3.1.x/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessagesRenderer.java 2007-10-29
09:34:07 UTC (rev 3588)
@@ -4,17 +4,18 @@
package org.richfaces.renderkit.html;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Iterator;
-import java.util.Set;
+import java.util.List;
import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIComponent;
import javax.faces.component.UIMessages;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.ajax4jsf.resource.InternetResource;
import org.richfaces.component.UIRichMessages;
import org.richfaces.renderkit.RichMessageBaseRenderer;
@@ -26,55 +27,6 @@
private boolean isWroteTable = false;
- private final InternetResource[] styles =
{getResource("/org/richfaces/renderkit/html/css/msgs.css")};
-
- private InternetResource[] stylesAll = null;
-
-
- protected InternetResource[] getStyles(){
-
- synchronized (this){
-
- if(stylesAll == null){
-
- InternetResource[] rsrcs = super.getStyles();
- boolean ignoreSuper = rsrcs == null || rsrcs.length == 0;
- boolean ignoreThis = styles == null || styles.length == 0;
-
- if(ignoreSuper){
-
- if (ignoreThis) {
- stylesAll = new InternetResource[0];
- } else {
- stylesAll = styles;
- }
-
- }else{
-
- if(ignoreThis){
- stylesAll = rsrcs;
- }else{
-
- Set rsrcsSet = new java.util.LinkedHashSet();
- for(int i = 0; i < rsrcs.length; i++ ){
- rsrcsSet.add(rsrcs[i]);
- }
-
- for(int i = 0; i < styles.length; i++ ){
- rsrcsSet.add(styles[i]);
- }
-
- stylesAll = (InternetResource[]) rsrcsSet.toArray(new
InternetResource[rsrcsSet.size()]);
- }
-
- }
-
- }
- }
-
- return stylesAll;
- }
-
protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
String forIds = null;
@@ -101,6 +53,11 @@
boolean isDisplayNone = (!messagesIter.hasNext() && !uiMessages.isPassed()) ?
true : false;
+ if(!isDisplayNone){
+ String [] levels = uiMessages.getLevel().split(",");
+ acceptLevels = creatAcceptLevels(levels);
+ }
+
layout = (String)uiMessages.getAttributes().get("layout");
if((layout != null) && (layout.equals("table"))){
@@ -127,6 +84,7 @@
while(messagesIter.hasNext()){
FacesMessage facesMsg = (FacesMessage)(messagesIter.next());
+
renderBody(uiMessages, context, writer, facesMsg);
}
@@ -141,6 +99,8 @@
}
+
+
public void renderLabelHtml(UIComponent component, FacesContext context, ResponseWriter
writer,
FacesMessage facesMsg, String labelClass, String labelStyle, String passLabel)
throws IOException {
@@ -274,24 +234,26 @@
if(uiMessages.isPassed() || facesMsg != null ){
- if(isWroteTable){
- writer.startElement(HTML.TR_ELEMENT, uiMessages);
- writer.startElement(HTML.td_ELEM, uiMessages);
- }else{
- writer.startElement("dt", uiMessages);
- }
-
- outerStyles(uiMessages, context, writer, facesMsg);
- renderMarkerFacet(uiMessages, context, writer, facesMsg);
- renderLabel(uiMessages, context, writer, facesMsg);
-
- if(isWroteTable){
- writer.endElement(HTML.td_ELEM);
- writer.endElement(HTML.TR_ELEMENT);
- }else{
- writer.endElement("dt");
- }
+ if(isAcceptableMessage(facesMsg)){
+ if(isWroteTable){
+ writer.startElement(HTML.TR_ELEMENT, uiMessages);
+ writer.startElement(HTML.td_ELEM, uiMessages);
+ }else{
+ writer.startElement("dt", uiMessages);
+ }
+
+ outerStyles(uiMessages, context, writer, facesMsg);
+ renderMarkerFacet(uiMessages, context, writer, facesMsg);
+ renderLabel(uiMessages, context, writer, facesMsg);
+
+ if(isWroteTable){
+ writer.endElement(HTML.td_ELEM);
+ writer.endElement(HTML.TR_ELEMENT);
+ }else{
+ writer.endElement("dt");
+ }
+ }
}
}