Author: alexsmirnov
Date: 2011-01-31 17:26:32 -0500 (Mon, 31 Jan 2011)
New Revision: 21344
Added:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageForRender.java
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageTransformer.java
Removed:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-message.js
Modified:
trunk/ui/validator/ui/src/main/config/faces-config.xml
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageRendererBase.java
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/FormClientValidatorRenderer.java
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
Log:
RESOLVED - issue RF-10309: CSV: not working JSF validators.
https://issues.jboss.org/browse/RF-10309
Modified: trunk/ui/validator/ui/src/main/config/faces-config.xml
===================================================================
--- trunk/ui/validator/ui/src/main/config/faces-config.xml 2011-01-31 22:26:18 UTC (rev
21343)
+++ trunk/ui/validator/ui/src/main/config/faces-config.xml 2011-01-31 22:26:32 UTC (rev
21344)
@@ -20,7 +20,11 @@
<client-behavior-renderer-type>org.richfaces.ClientValidatorRenderer</client-behavior-renderer-type>
<client-behavior-renderer-class>org.richfaces.renderkit.html.ClientValidatorRenderer</client-behavior-renderer-class>
</client-behavior-renderer>
- </render-kit>
+ <client-behavior-renderer>
+
<client-behavior-renderer-type>org.richfaces.FormValidatorRenderer</client-behavior-renderer-type>
+
<client-behavior-renderer-class>org.richfaces.renderkit.html.FormClientValidatorRenderer</client-behavior-renderer-class>
+ </client-behavior-renderer>
+ </render-kit>
<faces-config-extension>
<cdk:taglib>
<cdk:shortName>csv</cdk:shortName>
Added: trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageForRender.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageForRender.java
(rev 0)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageForRender.java 2011-01-31
22:26:32 UTC (rev 21344)
@@ -0,0 +1,79 @@
+package org.richfaces.renderkit;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
+
+public class MessageForRender {
+
+ private final FacesMessage msg;
+ private final String sourceId;
+
+ public MessageForRender(FacesMessage msg, String sourceId) {
+ this.msg = msg;
+ this.sourceId = sourceId;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return
+ * @see javax.faces.application.FacesMessage#getDetail()
+ */
+ public String getDetail() {
+ return this.msg.getDetail();
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return
+ * @see javax.faces.application.FacesMessage#getSeverity()
+ */
+ public Severity getSeverity() {
+ return this.msg.getSeverity();
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return
+ * @see javax.faces.application.FacesMessage#getSummary()
+ */
+ public String getSummary() {
+ return this.msg.getSummary();
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return
+ * @see javax.faces.application.FacesMessage#isRendered()
+ */
+ public boolean isRendered() {
+ return this.msg.isRendered();
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @see javax.faces.application.FacesMessage#rendered()
+ */
+ public void rendered() {
+ this.msg.rendered();
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the sourceId
+ */
+ public String getSourceId() {
+ return sourceId;
+ }
+}
Property changes on:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageForRender.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageRendererBase.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageRendererBase.java 2011-01-31
22:26:18 UTC (rev 21343)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageRendererBase.java 2011-01-31
22:26:32 UTC (rev 21344)
@@ -64,9 +64,9 @@
FacesMessage.SEVERITY_ERROR, attrs("error", "err", null),
FacesMessage.SEVERITY_FATAL,
attrs("fatal", "ftl", null));
- protected Iterator<FacesMessage> getMessages(FacesContext context, String
forClientId, UIComponent component) {
+ protected Iterator<MessageForRender> getMessages(FacesContext context, String
forClientId, UIComponent component) {
- Iterator<FacesMessage> msgIter;
+ Iterator<MessageForRender> msgIter;
if (forClientId != null) {
@@ -76,20 +76,32 @@
if (result == null) {
msgIter = Iterators.emptyIterator();
} else {
- msgIter = context.getMessages(result.getClientId(context));
+ String clientId = result.getClientId(context);
+ msgIter = getMessagesForId(context, clientId);
}
} else {
- msgIter = context.getMessages(null);
+ msgIter = getMessagesForId(context, null);
}
} else {
- msgIter = context.getMessages();
+ msgIter = Iterators.emptyIterator();
+ Iterator<String> clientIdsWithMessages =
context.getClientIdsWithMessages();
+ while (clientIdsWithMessages.hasNext()) {
+ String clientId = (String) clientIdsWithMessages.next();
+ msgIter = Iterators.concat(msgIter,getMessagesForId(context, clientId));
+ }
}
return msgIter;
}
+ private Iterator<MessageForRender> getMessagesForId(FacesContext context,
String clientId) {
+ Iterator<MessageForRender> msgIter;
+ msgIter = Iterators.transform(context.getMessages(clientId),new
MessageTransformer(null==clientId?"":clientId));
+ return msgIter;
+ }
+
/**
* <p class="changed_added_4_0">
* TODO - make Generator aware of Iterator.
@@ -99,24 +111,29 @@
* @param component
* @return
*/
- protected Iterable<FacesMessage> getVisibleMessages(FacesContext context,
UIComponent component) {
+ protected Iterable<MessageForRender> getVisibleMessages(FacesContext context,
UIComponent component) {
String forId = getFor(component);
- Iterator<FacesMessage> messages = getMessages(context, forId, component);
- UnmodifiableIterator<FacesMessage> filteredMessages =
+ Iterator<MessageForRender> messages = getMessages(context, forId,
component);
+ UnmodifiableIterator<MessageForRender> filteredMessages =
Iterators.filter(messages, getMessagesLevelFilter(context, component));
return Lists.newArrayList(filteredMessages);
}
- private Predicate<FacesMessage> getMessagesLevelFilter(FacesContext context,
UIComponent component) {
+ private Predicate<MessageForRender> getMessagesLevelFilter(FacesContext
context, UIComponent component) {
final Severity level = getLevel(component);
final boolean displayAll = component instanceof UIMessages;
- Predicate<FacesMessage> predicate = new Predicate<FacesMessage>() {
+ final boolean redisplay =
Boolean.TRUE.equals(component.getAttributes().get("redisplay"));
+ Predicate<MessageForRender> predicate = new
Predicate<MessageForRender>() {
private int count = 0;
- public boolean apply(FacesMessage input) {
- if(input.getSeverity().compareTo(level) >= 0){
- return displayAll||0 == count++;
+
+ public boolean apply(MessageForRender input) {
+ if (redisplay || !input.isRendered()) {
+ if (input.getSeverity().compareTo(level) >= 0) {
+ return displayAll || 0 == count++;
+ }
+
}
return false;
}
@@ -150,7 +167,7 @@
protected void encodeMessage(FacesContext facesContext, UIComponent component, Object
msg) throws IOException {
// TODO fix generator to properly detect iteration variable type
- FacesMessage message = (FacesMessage) msg;
+ MessageForRender message = (MessageForRender) msg;
String summary = message.getSummary();
String detail = message.getDetail();
boolean showSummary = true;
@@ -165,6 +182,8 @@
showDetail = uiMessages.isShowDetail();
}
ResponseWriter responseWriter = facesContext.getResponseWriter();
+ // Message id
+ responseWriter.writeAttribute("id",
component.getClientId()+':'+message.getSourceId(),null);
// tooltip
boolean wroteTooltip =
Boolean.TRUE.equals(component.getAttributes().get("tooltip"));
if(wroteTooltip && !Strings.isNullOrEmpty(summary)){
@@ -176,6 +195,7 @@
if (showDetail) {
writeMessageLabel(responseWriter, detail, "rf-msg-des");
}
+ message.rendered();
}
private void writeMessageLabel(ResponseWriter responseWriter, String label, String
styleClass) throws IOException {
@@ -219,7 +239,7 @@
}
protected String getMsgClass(FacesContext facesContext, UIComponent component, Object
msg) throws IOException {
- FacesMessage message = (FacesMessage) msg;
+ MessageForRender message = (MessageForRender) msg;
SeverityAttributes severityAttributes = SEVERITY_MAP.get(message.getSeverity());
String styleClass =
buildSeverityAttribute(component, severityAttributes.skinClass,
severityAttributes.classAttribute, ' ');
@@ -227,7 +247,7 @@
}
protected String getMsgStyle(FacesContext facesContext, UIComponent component, Object
msg) throws IOException {
- FacesMessage message = (FacesMessage) msg;
+ MessageForRender message = (MessageForRender) msg;
SeverityAttributes severityAttributes = SEVERITY_MAP.get(message.getSeverity());
String style =
buildSeverityAttribute(component, severityAttributes.skinStyle,
severityAttributes.styleAttribute, ';');
@@ -251,7 +271,7 @@
static SeverityAttributes attrs(String attPrefix, String skinSuffix, String
skinStyle) {
SeverityAttributes attrs =
- new SeverityAttributes(attPrefix + "Style", attPrefix +
"Class", "rf-msg-" + skinSuffix, skinStyle, null,
+ new SeverityAttributes(attPrefix + "Style", attPrefix +
"Class", skinStyle, "rf-msg-" + skinSuffix, null,
null);
return attrs;
}
Added:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageTransformer.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageTransformer.java
(rev 0)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageTransformer.java 2011-01-31
22:26:32 UTC (rev 21344)
@@ -0,0 +1,19 @@
+package org.richfaces.renderkit;
+
+import javax.faces.application.FacesMessage;
+
+import com.google.common.base.Function;
+
+public class MessageTransformer implements Function<FacesMessage, MessageForRender>
{
+
+ private final String sourceId;
+
+ public MessageTransformer(String sourceId) {
+ this.sourceId = sourceId;
+ }
+
+ public MessageForRender apply(FacesMessage input) {
+ return new MessageForRender(input, sourceId);
+ }
+
+}
Property changes on:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageTransformer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/FormClientValidatorRenderer.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/FormClientValidatorRenderer.java 2011-01-31
22:26:18 UTC (rev 21343)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/FormClientValidatorRenderer.java 2011-01-31
22:26:32 UTC (rev 21344)
@@ -32,6 +32,6 @@
*/
public class FormClientValidatorRenderer extends ClientBehaviorRenderer {
- public static final String
RENDERER_TYPE="orf.richfaces.FormValidatorRenderer";
+ public static final String
RENDERER_TYPE="org.richfaces.FormValidatorRenderer";
}
Modified:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js 2011-01-31
22:26:18 UTC (rev 21343)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js 2011-01-31
22:26:32 UTC (rev 21344)
@@ -49,30 +49,28 @@
};
var
severetyClasses=["rf-msg-inf","rf-msg-wrn","rf-msg-err","rf-msg-ftl"];
- var componentHash = {};
- var componentIndex = 0;
var onMessage = function (event, element, data) {
var content = $(rf.getDomElement(this.id));
+ var sourceId = data.sourceId;
+ var message = data.message;
if (!this.options.forComponentId) {
- var index = componentHash[data.sourceId];
- if (typeof index != undefined) {
- $(rf.getDomElement(this.id+index)).remove();
+ if (!message) {
+ // rf.csv.clearMessage
+ $(rf.getDomElement(this.id+':'+sourceId)).remove();
+ } else {
+ renderMessage.call(this,sourceId,message);
}
- componentIndex ++;
- renderMessage.call(this,componentIndex,data.message);
- componentHash[data.sourceId] = componentIndex;
-
- } else if (this.options.forComponentId==data.sourceId) {
+ } else if (this.options.forComponentId === sourceId) {
content.empty();
- renderMessage.call(this,0,data.message);
+ renderMessage.call(this,sourceId,message);
}
}
var renderMessage = function(index,message){
if(message && message.severity >= this.options.level){
var content = $(rf.getDomElement(this.id));
- var msgContent = "<span
class='"+severetyClasses[message.severity]+"'
id='"+this.id+index+"'";
+ var msgContent = "<span
class='"+severetyClasses[message.severity]+"'
id='"+this.id+':'+index+"'";
if(message.summary){
if(this.options.tooltip){
msgContent = msgContent+"
title='"+message.summary+"'>";
Modified:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-01-31
22:26:18 UTC (rev 21343)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-01-31
22:26:32 UTC (rev 21344)
@@ -69,6 +69,7 @@
var value = __getValue(element || id);
var convertedValue;
var converter = params.c;
+ rf.csv.clearMessage(id);
if (converter) {
try {
if (converter.f)
@@ -99,8 +100,6 @@
}
if(!params.da && params.a){
params.a.call(element,event,id);
- } else {
- rf.csv.clearMessage(id);
}
return true;
},
@@ -162,8 +161,8 @@
});
var validateRange = function(value,label,params,msg) {
- var isMinSet = typeof params.minimum == "number" ;//&& params.minimum
>0;
- var isMaxSet = typeof params.maximum == "number" ;//&& params.maximum
>0;
+ var isMinSet = typeof params.minimum === "number" ;//&&
params.minimum >0;
+ var isMaxSet = typeof params.maximum === "number" ;//&&
params.maximum >0;
if (isMaxSet && value > params.maximum) {
throw
rf.csv.interpolateMessage(msg,isMinSet?[params.minimum,params.maximum,label]:[params.maximum,label]);
Deleted:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-message.js
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-message.js 2011-01-31
22:26:18 UTC (rev 21343)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-message.js 2011-01-31
22:26:32 UTC (rev 21344)
@@ -1,77 +0,0 @@
-(function($, rf) {
-
- rf.ui = rf.ui || {};
-
- // Constructor definition
- rf.ui.Base = function(componentId, options, defaultOptions) {
- this.namespace = "."+rf.Event.createNamespace(this.name, componentId);
- // call constructor of parent class
- $super.constructor.call(this, componentId);
- this.options = $.extend(this.options, defaultOptions, options);
- this.attachToDom();
- this.__bindEventHandlers();
- };
-
- // Extend component class and add protected methods from parent class to our container
- rf.BaseComponent.extend(rf.ui.Base);
-
- // define super class link
- var $super = rf.ui.Base.$super;
-
- $.extend(rf.ui.Base.prototype, {
- __bindEventHandlers: function () {
- },
- destroy: function () {
- rf.Event.unbindById(this.id, this.namespace);
- $super.destroy.call(this);
- }
- });
-
-})(jQuery, window.RichFaces || (window.RichFaces={}));
-
-(function($, rf) {
-
- // Constructor definition
- rf.ui.Message = function(componentId, options) {
- // call constructor of parent class
- $super.constructor.call(this, componentId, options, defaultOptions);
- };
-
- // Extend component class and add protected methods from parent class to our container
- rf.ui.Base.extend(rf.ui.Message);
-
- // define super class link
- var $super = rf.ui.Message.$super;
-
- var defaultOptions = {
-
- };
-
- var componentHash = {};
- var componentIndex = 0;
-
- var onMessage = function (event, element, data) {
- if (!this.options.forComponentId) {
- var index = componentHash[data.sourceId];
- if (typeof index != undefined) {
- $(rf.getDomElement(this.id+index)).remove();
- }
- var content = content = $(rf.getDomElement(this.id));
-
- componentIndex ++;
- if (data.message) content.append('<li
id="'+this.id+componentIndex+'">'+data.message.summary+'</li>');
- componentHash[data.sourceId] = componentIndex;
-
- } else if (this.options.forComponentId==data.sourceId) {
- rf.getDomElement(this.id).innerHTML = data.message ?
'<li>'+data.message.summary+'</li>' : '';
- }
- }
-
- $.extend(rf.ui.Message.prototype, {
- name: "Message",
- __bindEventHandlers: function () {
- rf.Event.bind(window.document, rf.Event.MESSAGE_EVENT_TYPE+this.namespace, onMessage,
this);
- }
- });
-
-})(jQuery, window.RichFaces || (window.RichFaces={}));
\ No newline at end of file