Author: amarkhel
Date: 2009-05-28 08:39:30 -0400 (Thu, 28 May 2009)
New Revision: 14387
Added:
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/MessagesLevelEnum.java
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/RichMessageLevelHelper.java
Modified:
branches/community/3.3.X/ui/message/src/main/config/component/message.xml
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/UIRichMessage.java
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessageRenderer.java
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessagesRenderer.java
Log:
Fix RF-5145 RF-5107
Modified: branches/community/3.3.X/ui/message/src/main/config/component/message.xml
===================================================================
--- branches/community/3.3.X/ui/message/src/main/config/component/message.xml 2009-05-28
12:36:13 UTC (rev 14386)
+++ branches/community/3.3.X/ui/message/src/main/config/component/message.xml 2009-05-28
12:39:30 UTC (rev 14387)
@@ -59,10 +59,16 @@
<description>
A comma-separated list of messages categories which should be displayed. Default
value is "ALL".
</description>
- <defaultvalue>"ALL"</defaultvalue>
</property>
+ <property>
+ <name>minLevel</name>
+ <classname>java.lang.String</classname>
+ <description>
+ A minimum level of messages categories which should be displayed.
+ </description>
+ </property>
<property attachedstate="true" hidden="true">
<name>passedLabel</name>
<classname>java.lang.String</classname>
@@ -344,10 +350,17 @@
<description>
A comma-separated list of messages categories which should be displayed. Default
value is "ALL".
</description>
- <defaultvalue>"ALL"</defaultvalue>
</property>
<property>
+ <name>minLevel</name>
+ <classname>java.lang.String</classname>
+ <description>
+ A minimum level of messages categories which should be displayed.
+ </description>
+
+ </property>
+ <property>
<name>for</name>
<classname>java.lang.String</classname>
<description>
Added:
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/MessagesLevelEnum.java
===================================================================
---
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/MessagesLevelEnum.java
(rev 0)
+++
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/MessagesLevelEnum.java 2009-05-28
12:39:30 UTC (rev 14387)
@@ -0,0 +1,47 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.component;
+
+/**
+ * @author Andrey Markhel
+ * This class is enumeration of all possible
<code>FacesMessages.SEVERITY</code> levels of errors
+ *
+ */
+public enum MessagesLevelEnum {
+ PASSED, INFO, WARN, FATAL, ERROR;
+
+ /**
+ * This method return all levels of errors to be rendered(all with severity higher then
specified min level and also min level)
+ * @param level - string representation of minimum level of error should be rendered
+ * @return all levels of errors to be rendered(all with severity higher then specified
min level and also min level)
+ */
+ public static MessagesLevelEnum[] getHigherLevels(String level) {
+ MessagesLevelEnum [] all = values();
+ for (int i = 0; i < all.length; i++) {
+ if (all[i].name().equals(level.toUpperCase().trim())) {
+ MessagesLevelEnum [] levels = new MessagesLevelEnum [all.length - i];
+ System.arraycopy(all, i, levels, 0, all.length - i);
+ return levels;
+ }
+ }
+ return values();
+ }
+}
Property changes on:
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/MessagesLevelEnum.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/RichMessageLevelHelper.java
===================================================================
---
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/RichMessageLevelHelper.java
(rev 0)
+++
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/RichMessageLevelHelper.java 2009-05-28
12:39:30 UTC (rev 14387)
@@ -0,0 +1,81 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.component;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+/**
+ * @author Andrey Markhel
+ * This utility class used in determination levels of errors should be rendered.
+ *
+ */
+public class RichMessageLevelHelper {
+
+ private RichMessageLevelHelper(){
+
+ }
+
+ public static List<String> getSeverenities(UIComponent msg){
+ UIRichMessage richMessage = null;
+ UIRichMessages richMessages = null;
+ String level = null;
+ String minLevel = null;
+ if(msg instanceof UIRichMessages){
+ richMessages = (UIRichMessages)msg;
+ level = richMessages.getLevel();
+ minLevel = richMessages.getMinLevel();
+ }else if(msg instanceof UIRichMessage){
+ richMessage = (UIRichMessage)msg;
+ level = richMessage.getLevel();
+ minLevel = richMessage.getMinLevel();
+ }
+ if(level != null && minLevel != null){
+ System.err.println("ERROR: To properly working of component you must specify only
one attribbute(minLevel or level)");
+ }
+ if(null == level && null == minLevel){
+ level = "ALL";
+ }
+ List<String> severenities;
+ if (null != level) {
+ String[] levels = level.split(",");
+ severenities = new ArrayList<String>(levels.length);
+ for (int i = 0; i < levels.length; i++) {
+ String levelName = levels[i].toUpperCase().trim();
+ severenities.add(levelName);
+ }
+ } else if(null != minLevel){
+ String min = minLevel;
+ MessagesLevelEnum[] levels =
MessagesLevelEnum.getHigherLevels(min.toUpperCase().trim());
+ severenities = new ArrayList<String>(levels.length);
+ for (int i = 0; i < levels.length; i++) {
+ String levelName = levels[i].name().trim();
+ severenities.add(levelName);
+ }
+ }
+ else {
+ severenities = Collections.emptyList();
+ }
+ return severenities;
+ }
+}
Property changes on:
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/RichMessageLevelHelper.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/UIRichMessage.java
===================================================================
---
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/UIRichMessage.java 2009-05-28
12:36:13 UTC (rev 14386)
+++
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/UIRichMessage.java 2009-05-28
12:39:30 UTC (rev 14387)
@@ -35,6 +35,7 @@
public abstract class UIRichMessage extends UIMessage implements AjaxOutput{
private boolean isPassed = false;
+ private boolean ajaxRendered = true;
public boolean isPassed() {
return isPassed;
@@ -45,13 +46,11 @@
public abstract void setPassedLabel(String passedLabel);
public boolean isAjaxRendered() {
- return true;
+ return ajaxRendered;
}
public void setAjaxRendered(boolean ajaxRendered) {
- if(!ajaxRendered){
- new IllegalArgumentException();
- }
+ this.ajaxRendered = ajaxRendered;
}
public void decode(FacesContext context) {
@@ -72,6 +71,30 @@
public abstract String getLevel();
public abstract void setLevel(String level);
+
+ public abstract String getMinLevel();
-
+ public abstract void setMinLevel(String minLevel);
+
+ private Object[] values;
+
+ public Object saveState(FacesContext context) {
+
+ if (values == null) {
+ values = new Object[3];
+ }
+
+ values[0] = super.saveState(context);
+ values[1] = this.ajaxRendered;
+ return (values);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public void restoreState(FacesContext context, Object state) {
+
+ values = (Object[]) state;
+ super.restoreState(context, values[0]);
+ ajaxRendered = (Boolean) values[1];
+ }
}
Modified:
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java
===================================================================
---
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java 2009-05-28
12:36:13 UTC (rev 14386)
+++
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/component/UIRichMessages.java 2009-05-28
12:39:30 UTC (rev 14387)
@@ -25,7 +25,6 @@
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -39,6 +38,7 @@
import javax.faces.context.FacesContext;
import org.ajax4jsf.component.AjaxOutput;
+import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.renderkit.RendererUtils;
/**
@@ -51,7 +51,7 @@
private String forVal = null;
private boolean updated = false;
-
+ private boolean ajaxRendered = true;
private List<FacesMessageWithId> renderedMessages;
/**
@@ -99,8 +99,12 @@
}
public boolean isAjaxRendered() {
- return true;
+ return ajaxRendered;
}
+
+ public void setAjaxRendered(boolean ajaxRendered) {
+ this.ajaxRendered = ajaxRendered;
+ }
public Iterator<FacesMessage> getMessages(FacesContext context) {
String forInputId = getFor();
@@ -189,6 +193,10 @@
if (severenities.size() == 0 || severenities.contains("ALL")) {
return true;
}
+ AjaxContext ac = AjaxContext.getCurrentInstance(FacesContext.getCurrentInstance());
+ if(ac.isAjaxRequest() && !this.isAjaxRendered()){
+ return false;
+ }
Severity severity = message.getSeverity();
for (Object key : FacesMessage.VALUES_MAP.keySet()) {
Severity sev = (Severity) FacesMessage.VALUES_MAP.get(key);
@@ -199,12 +207,6 @@
return false;
}
- public void setAjaxRendered(boolean ajaxRendered) {
- if (!ajaxRendered) {
- new IllegalArgumentException();
- }
- }
-
@Override
public void encodeBegin(FacesContext context) throws IOException {
if (!isUpdated()) {
@@ -216,21 +218,13 @@
public abstract String getLevel();
public abstract void setLevel(String level);
+
+ public abstract String getMinLevel();
+ public abstract void setMinLevel(String level);
+
public List<String> getSeverenities() {
- String level = getLevel();
- List<String> severenities;
- if (null != level) {
- String[] levels = level.split(",");
- severenities = new ArrayList<String>(levels.length);
- for (int i = 0; i < levels.length; i++) {
- String levelName = levels[i].toUpperCase().trim();
- severenities.add(levelName);
- }
- } else {
- severenities = Collections.emptyList();
- }
- return severenities;
+ return RichMessageLevelHelper.getSeverenities(this);
}
private Object[] values;
@@ -238,12 +232,13 @@
public Object saveState(FacesContext context) {
if (values == null) {
- values = new Object[3];
+ values = new Object[4];
}
values[0] = super.saveState(context);
values[1] = this.forVal;
- values[2] = saveAttachedState(context, getRenderedMessages());
+ values[2] = this.ajaxRendered;
+ values[3] = saveAttachedState(context, getRenderedMessages());
return (values);
}
@@ -254,8 +249,9 @@
values = (Object[]) state;
super.restoreState(context, values[0]);
forVal = (String) values[1];
+ ajaxRendered = (Boolean) values[2];
setRenderedMessages((List<FacesMessageWithId>) restoreAttachedState(
- context, values[2]));
+ context, values[3]));
}
/**
Modified:
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessageRenderer.java
===================================================================
---
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessageRenderer.java 2009-05-28
12:36:13 UTC (rev 14386)
+++
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessageRenderer.java 2009-05-28
12:39:30 UTC (rev 14387)
@@ -31,6 +31,7 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.RichMessageLevelHelper;
import org.richfaces.component.UIRichMessage;
import org.richfaces.renderkit.RichMessageBaseRenderer;
@@ -60,16 +61,13 @@
msgIter = getMessageIterator(context, forClientId, msgComponent);
writer.startElement(HTML.SPAN_ELEM, msgComponent);
getUtils().writeAttribute(writer, HTML.id_ATTRIBUTE,
msgComponent.getClientId(context));
-
if(!msgIter.hasNext() && msgComponent.isPassed()){
encodingUIContent(msgComponent, context, null);
}else if(msgIter.hasNext() ){
-
- FacesMessage message = (FacesMessage)msgIter.next();
- encodingUIContent(msgComponent, context, message);
-
+ FacesMessage message = (FacesMessage)msgIter.next();
+ encodingUIContent(msgComponent, context, message);
}
writer.endElement(HTML.SPAN_ELEM);
@@ -79,8 +77,10 @@
protected void encodingUIContent(UIRichMessage uiMsg, FacesContext context, FacesMessage
facesMsg) throws IOException{
ResponseWriter writer = context.getResponseWriter();
-
- List<String> acceptLevels =
creatAcceptLevels(uiMsg.getLevel().split(","));
+
+ List<String> severenities = RichMessageLevelHelper.getSeverenities(uiMsg);
+ String[] levels = new String[severenities .size()];
+ List<String> acceptLevels = creatAcceptLevels(severenities.toArray(levels));
if(isAcceptableMessage(facesMsg, acceptLevels)){
outerStyles(uiMsg, context, writer, facesMsg);
renderMarkerFacet(uiMsg,context, writer,facesMsg);
Modified:
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessagesRenderer.java
===================================================================
---
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessagesRenderer.java 2009-05-28
12:36:13 UTC (rev 14386)
+++
branches/community/3.3.X/ui/message/src/main/java/org/richfaces/renderkit/html/HtmlRichMessagesRenderer.java 2009-05-28
12:39:30 UTC (rev 14387)
@@ -80,7 +80,6 @@
}
// messagesIter = getMessageIterator(context, forIds, component);
-
if(!messagesIter.hasNext()){
renderBody(uiMessages, context, writer, null,isWroteTable);
}else{