JBoss Rich Faces SVN: r21473 - in trunk/ui/validator/ui/src/main: resources/META-INF/resources/org.richfaces and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: jbalunas(a)redhat.com
Date: 2011-02-04 15:37:34 -0500 (Fri, 04 Feb 2011)
New Revision: 21473
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageRendererBase.java
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss
Log:
RF-10371 Updated css name for msg
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-02-04 20:20:09 UTC (rev 21472)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/MessageRendererBase.java 2011-02-04 20:37:34 UTC (rev 21473)
@@ -193,7 +193,7 @@
writeMessageLabel(responseWriter, summary, "rf-msg-sum");
}
if (showDetail) {
- writeMessageLabel(responseWriter, detail, "rf-msg-des");
+ writeMessageLabel(responseWriter, detail, "rf-msg-det");
}
message.rendered();
}
Modified: trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss
===================================================================
--- trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss 2011-02-04 20:20:09 UTC (rev 21472)
+++ trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss 2011-02-04 20:37:34 UTC (rev 21473)
@@ -42,5 +42,5 @@
.rf-msg-sum{ /*Summary*/
}
-.rf-msg-des{ /*Description*/
+.rf-msg-det{ /*Description*/
}
15 years, 2 months
JBoss Rich Faces SVN: r21472 - trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2011-02-04 15:20:09 -0500 (Fri, 04 Feb 2011)
New Revision: 21472
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/menuitem.js
Log:
https://issues.jboss.org/browse/RF-10071
Modified: trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/menuitem.js
===================================================================
--- trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/menuitem.js 2011-02-04 20:01:27 UTC (rev 21471)
+++ trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/menuitem.js 2011-02-04 20:20:09 UTC (rev 21472)
@@ -47,6 +47,10 @@
},
__clickHandler : function(e) {
+ if ($(e.target).is(":input:not(:button):not(:reset):not(:submit)")) {
+ return;
+ }
+
var parentMenu = this.__getParentMenu();
if (parentMenu) {
parentMenu.processItem(this.element);
15 years, 2 months
JBoss Rich Faces SVN: r21471 - trunk/examples/misc-demo/src/main/webapp/pages.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2011-02-04 15:01:27 -0500 (Fri, 04 Feb 2011)
New Revision: 21471
Modified:
trunk/examples/misc-demo/src/main/webapp/pages/index.xhtml
Log:
https://issues.jboss.org/browse/RF-10036
Modified: trunk/examples/misc-demo/src/main/webapp/pages/index.xhtml
===================================================================
--- trunk/examples/misc-demo/src/main/webapp/pages/index.xhtml 2011-02-04 20:01:06 UTC (rev 21470)
+++ trunk/examples/misc-demo/src/main/webapp/pages/index.xhtml 2011-02-04 20:01:27 UTC (rev 21471)
@@ -28,6 +28,8 @@
<br />
<h:outputText value="#{fn:findComponent('input').value}" />
<br />
+ <h:outputText value="#{fn:toScript('input')}" />
+ <br />
Roles:
<h:outputText rendered="#{fn:isUserInRole('admin, user')}"
15 years, 2 months
JBoss Rich Faces SVN: r21470 - trunk/ui/misc/ui/src/main/java/org/richfaces/function.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2011-02-04 15:01:06 -0500 (Fri, 04 Feb 2011)
New Revision: 21470
Modified:
trunk/ui/misc/ui/src/main/java/org/richfaces/function/RichFunction.java
Log:
https://issues.jboss.org/browse/RF-10036
Modified: trunk/ui/misc/ui/src/main/java/org/richfaces/function/RichFunction.java
===================================================================
--- trunk/ui/misc/ui/src/main/java/org/richfaces/function/RichFunction.java 2011-02-04 19:23:22 UTC (rev 21469)
+++ trunk/ui/misc/ui/src/main/java/org/richfaces/function/RichFunction.java 2011-02-04 20:01:06 UTC (rev 21470)
@@ -27,6 +27,7 @@
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.cdk.annotations.Function;
import org.richfaces.renderkit.util.CoreAjaxRendererUtils;
import org.richfaces.renderkit.util.RendererUtils;
@@ -139,4 +140,9 @@
return false;
}
+
+ @Function
+ public static String toScript(Object o) {
+ return ScriptUtils.toScript(o);
+ }
}
15 years, 2 months
JBoss Rich Faces SVN: r21469 - in trunk/archetypes/rf-gae-sample: src/main/resources/archetype-resources and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: jbalunas(a)redhat.com
Date: 2011-02-04 14:23:22 -0500 (Fri, 04 Feb 2011)
New Revision: 21469
Modified:
trunk/archetypes/rf-gae-sample/readme.txt
trunk/archetypes/rf-gae-sample/src/main/resources/archetype-resources/readme.txt
trunk/archetypes/rf-gae-sample/src/main/resources/archetype-resources/src/main/webapp-gae/WEB-INF/appengine-web.xml
Log:
RF-9418 updated GAE archetype application name default
Modified: trunk/archetypes/rf-gae-sample/readme.txt
===================================================================
--- trunk/archetypes/rf-gae-sample/readme.txt 2011-02-04 18:46:35 UTC (rev 21468)
+++ trunk/archetypes/rf-gae-sample/readme.txt 2011-02-04 19:23:22 UTC (rev 21469)
@@ -14,7 +14,7 @@
*BEFORE NEXT STEP:
-- You should setup your GAE account at http://appspot.com
- -- Register your new application there. By default the applications name is "rf-${artifactId}"
+ -- Register your new application there. By default the applications name is "${artifactId}"
-- Download and install the GAE SDK for deployment and local server tools
3) Execute appcfg from GAE SDK to publish to your account:
Modified: trunk/archetypes/rf-gae-sample/src/main/resources/archetype-resources/readme.txt
===================================================================
--- trunk/archetypes/rf-gae-sample/src/main/resources/archetype-resources/readme.txt 2011-02-04 18:46:35 UTC (rev 21468)
+++ trunk/archetypes/rf-gae-sample/src/main/resources/archetype-resources/readme.txt 2011-02-04 19:23:22 UTC (rev 21469)
@@ -5,7 +5,7 @@
*BEFORE NEXT STEP:
-- You should setup your GAE account at http://appspot.com
- -- Register your new application there. By default the applications name is "rf-${artifactId}"
+ -- Register your new application there. By default the applications name is "${artifactId}"
-- Download and install the GAE SDK for deployment and local server tools
3) Execute appcfg from GAE SDK to publish to your account:
Modified: trunk/archetypes/rf-gae-sample/src/main/resources/archetype-resources/src/main/webapp-gae/WEB-INF/appengine-web.xml
===================================================================
--- trunk/archetypes/rf-gae-sample/src/main/resources/archetype-resources/src/main/webapp-gae/WEB-INF/appengine-web.xml 2011-02-04 18:46:35 UTC (rev 21468)
+++ trunk/archetypes/rf-gae-sample/src/main/resources/archetype-resources/src/main/webapp-gae/WEB-INF/appengine-web.xml 2011-02-04 19:23:22 UTC (rev 21469)
@@ -3,7 +3,7 @@
#set( $symbol_escape = '\' )
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
- <application>rf-${artifactId}</application>
+ <application>${artifactId}</application>
<version>1</version>
<sessions-enabled>true</sessions-enabled>
<system-properties>
15 years, 2 months
JBoss Rich Faces SVN: r21468 - trunk/cdk/attributes/src/main/resources/META-INF/cdk/attributes.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2011-02-04 13:46:35 -0500 (Fri, 04 Feb 2011)
New Revision: 21468
Modified:
trunk/cdk/attributes/src/main/resources/META-INF/cdk/attributes/command-button-props.xml
Log:
https://issues.jboss.org/browse/RF-10115
Modified: trunk/cdk/attributes/src/main/resources/META-INF/cdk/attributes/command-button-props.xml
===================================================================
--- trunk/cdk/attributes/src/main/resources/META-INF/cdk/attributes/command-button-props.xml 2011-02-04 18:44:31 UTC (rev 21467)
+++ trunk/cdk/attributes/src/main/resources/META-INF/cdk/attributes/command-button-props.xml 2011-02-04 18:46:35 UTC (rev 21468)
@@ -189,9 +189,8 @@
<property>
<description>
- Type of button to create. Valid values are "submit", "button",
- and "reset". If not specified, or not a valid value, the default
- value is "submit".
+ Type of button to create. Can be one of "submit", "button", "image" and "reset".
+ If not specified, the default value is "submit".
</description>
<display-name>Button Type</display-name>
<icon />
15 years, 2 months
JBoss Rich Faces SVN: r21467 - in trunk: ui/input/ui/src/main/resources/META-INF/resources/org.richfaces and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2011-02-04 13:44:31 -0500 (Fri, 04 Feb 2011)
New Revision: 21467
Modified:
trunk/examples/input-demo/src/main/webapp/examples/select.xhtml
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js
Log:
RF-10164 select: inconsistency of usage arrow button and showPopup api method.
Modified: trunk/examples/input-demo/src/main/webapp/examples/select.xhtml
===================================================================
--- trunk/examples/input-demo/src/main/webapp/examples/select.xhtml 2011-02-04 18:41:40 UTC (rev 21466)
+++ trunk/examples/input-demo/src/main/webapp/examples/select.xhtml 2011-02-04 18:44:31 UTC (rev 21467)
@@ -1,46 +1,61 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:in="http://richfaces.org/input">
-<f:view contentType="text/html" />
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:in="http://richfaces.org/input"
+ xmlns:misc="http://richfaces.org/misc">
+<f:view contentType="text/html"/>
<h:head>
- <title>Select</title>
+ <title>Select</title>
</h:head>
<h:body>
- <h:form id="form">
- <div id="scroll" style="width: 400px; height:100px; overflow:auto;" >
- <fieldset>
- <legend>Select Test App</legend>
- <in:select id="select" enableManualInput="true" defaultLabel="Select Value ..." value="#{inputBean.value}">
- <f:selectItem itemLabel="Label#1" itemValue="Value#1"/>
- <f:selectItem itemLabel="Label#2" itemValue="Value#2"/>
- <f:selectItem itemLabel="Label#3" itemValue="Value#3"/>
- <f:selectItem itemLabel="Label#4" itemValue="Value#4"/>
- <f:selectItem itemLabel="Label#5" itemValue="Value#5"/>
- <f:selectItem itemLabel="Label#6" itemValue="Value#6"/>
- <f:selectItem itemLabel="Label#7" itemValue="Value#7"/>
- <f:selectItem itemLabel="Label#8" itemValue="Value#8"/>
- <f:selectItem itemLabel="Label#9" itemValue="Value#9"/>
- <f:selectItem itemLabel="Label#10" itemValue="Value#10"/>
- <f:selectItem itemLabel="Label#11" itemValue="Value#11"/>
- <f:selectItem itemLabel="Label#12" itemValue="Value#12"/>
- <f:selectItem itemLabel="Label#13" itemValue="Value#13"/>
- <f:selectItem itemLabel="Label#14" itemValue="Value#14"/>
- <f:ajax event="change" execute="@form" render="out"/>
- </in:select>
- </fieldset>
- <h:commandButton value="submit">
- <f:ajax execute="@form" render="select out"/>
- </h:commandButton>
- </div>
- <h:panelGroup id="out">
- <h:outputText value="Selected Value: #{inputBean.value}"/>
- </h:panelGroup>
- </h:form>
+ <h:form id="form">
+ <div id="scroll" style="width: 400px; height:100px; overflow:auto;">
+ <fieldset>
+ <legend>Select Test App</legend>
+ <in:select id="select" openOnEdit="true" enableManualInput="true" defaultLabel="Select Value ..."
+ value="#{inputBean.value}">
+ <f:selectItem itemLabel="Label#1" itemValue="Value#1"/>
+ <f:selectItem itemLabel="Label#2" itemValue="Value#2"/>
+ <f:selectItem itemLabel="Label#3" itemValue="Value#3"/>
+ <f:selectItem itemLabel="Label#4" itemValue="Value#4"/>
+ <f:selectItem itemLabel="Label#5" itemValue="Value#5"/>
+ <f:selectItem itemLabel="Label#6" itemValue="Value#6"/>
+ <f:selectItem itemLabel="Label#7" itemValue="Value#7"/>
+ <f:selectItem itemLabel="Label#8" itemValue="Value#8"/>
+ <f:selectItem itemLabel="Label#9" itemValue="Value#9"/>
+ <f:selectItem itemLabel="Label#10" itemValue="Value#10"/>
+ <f:selectItem itemLabel="Label#11" itemValue="Value#11"/>
+ <f:selectItem itemLabel="Label#12" itemValue="Value#12"/>
+ <f:selectItem itemLabel="Label#13" itemValue="Value#13"/>
+ <f:selectItem itemLabel="Label#14" itemValue="Value#14"/>
+ <f:ajax event="change" execute="@form" render="out"/>
+ </in:select>
+ </fieldset>
+ <h:commandButton value="submit">
+ <f:ajax execute="@form" render="select out"/>
+ </h:commandButton>
+ </div>
+
+ <ul>
+ <li>
+ <h:commandButton value="ShowPopup"
+ onclick="#{misc:component('select')}.showPopup(); return false;"/>
+ </li>
+ <li>
+ <h:commandButton value="HidePopup"
+ onclick="#{misc:component('select')}.hidePopup(); return false;"/>
+ </li>
+
+
+ </ul>
+ <h:panelGroup id="out">
+ <h:outputText value="Selected Value: #{inputBean.value}"/>
+ </h:panelGroup>
+ </h:form>
</h:body>
</html>
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js 2011-02-04 18:41:40 UTC (rev 21466)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js 2011-02-04 18:44:31 UTC (rev 21467)
@@ -75,7 +75,7 @@
this.__updateItems();
this.__showPopup();
} else {
- this.hidePopup();
+ this.__hidePopup();
}
this.isMouseDown = true;
},
@@ -134,7 +134,7 @@
case rf.KEYS.ESC:
e.preventDefault();
if(visible) {
- this.hidePopup();
+ this.__hidePopup();
}
break;
@@ -257,9 +257,43 @@
this.popupList.show();
},
- hidePopup: function() {
+ __hidePopup: function() {
this.popupList.hide();
},
+
+ showPopup: function() {
+ if (!this.popupList.isVisible()) {
+ this.__updateItems();
+ this.__showPopup();
+ }
+ this.__setInputFocus();
+ if (!this.focused) {
+ if(this.__getValue() == this.defaultLabel) {
+ this.__setValue("");
+ }
+ this.focusValue = this.selValueInput.val();
+ this.focused = true;
+ this.invokeEvent.call(this, "focus", document.getElementById(this.id));
+ }
+ },
+
+ hidePopup: function() {
+ if (this.popupList.isVisible()){
+ this.__hidePopup();
+ var inputLabel = this.__getValue();
+
+ if (!inputLabel || inputLabel == "") {
+ this.__setValue(this.defaultLabel);
+ this.selValueInput.val("");
+ }
+
+ this.focused = false;
+ this.invokeEvent.call(this, "blur", document.getElementById(this.id));
+ if (this.focusValue != this.selValueInput.val()) {
+ this.invokeEvent.call(this, "change", document.getElementById(this.id));
+ }
+ }
+ },
processItem: function(item) {
var key = $(item).attr("id");
@@ -271,7 +305,7 @@
}
});
this.__setValue(label);
- this.hidePopup();
+ this.__hidePopup();
this.__setInputFocus();
this.__save();
@@ -303,7 +337,7 @@
},
onblur: function(e) {
- this.hidePopup();
+ this.__hidePopup();
var inputLabel = this.__getValue();
if(!inputLabel || inputLabel == "") {
15 years, 2 months
JBoss Rich Faces SVN: r21466 - trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2011-02-04 13:41:40 -0500 (Fri, 04 Feb 2011)
New Revision: 21466
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/tooltip.js
Log:
https://issues.jboss.org/browse/RF-9654
Modified: trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/tooltip.js
===================================================================
--- trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/tooltip.js 2011-02-04 18:37:54 UTC (rev 21465)
+++ trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/tooltip.js 2011-02-04 18:41:40 UTC (rev 21466)
@@ -118,34 +118,22 @@
this.popup = new RichFaces.ui.Popup(this.id, {
attachTo: this.target,
- attachToBody: false,
+ attachToBody: true,
positionType: "TOOLTIP",
positionOffset: this.options.offset,
jointPoint: this.options.jointPoint,
direction: this.options.direction
});
- var tooltip = this;
- function mouseMoveHandler(event) {
- tooltip.popup.show(event);
+ var targetElt = $(document.getElementById(this.target));
+
+ targetElt.bind(this.options.showEvent, $.proxy(this.__showHandler, this));
+
+ var hideFunction = $.proxy(this.__hideHandler, this);
+ targetElt.bind(this.options.hideEvent, hideFunction);
+ if (this.options.hideEvent == 'mouseleave') {
+ $(document.getElementById(this.id)).bind(this.options.hideEvent, hideFunction);
}
-
- $(document.getElementById(this.target)).bind(this.options.showEvent, function (event) {
- tooltip.show(event);
-
- if (tooltip.options.followMouse) {
- $(document.getElementById(tooltip.target)).bind("mousemove", mouseMoveHandler);
- }
- });
-
- $(document.getElementById(tooltip.target)).bind(this.options.hideEvent, function () {
- tooltip.hide();
-
- if (tooltip.options.followMouse) {
- $(document.getElementById(tooltip.target)).unbind("mousemove", mouseMoveHandler);
- }
- });
-
},
/***************************** Public Methods ****************************************************************/
@@ -168,6 +156,18 @@
return this.__fireHide()
},
+ __hideHandler: function(event) {
+ if (event.type == 'mouseleave' && this.__isInside(event.relatedTarget)) {
+ return;
+ }
+
+ this.hide();
+
+ if (this.options.followMouse) {
+ $(document.getElementById(this.target)).unbind("mousemove", this.__mouseMoveHandler);
+ }
+ },
+
/**
* @private
* @return {void} TODO ...
@@ -179,6 +179,18 @@
});
},
+ __mouseMoveHandler: function(event) {
+ this.popup.show(event);
+ },
+
+ __showHandler: function(event) {
+ this.show(event);
+
+ if (this.options.followMouse) {
+ $(document.getElementById(this.target)).bind("mousemove", $.proxy(this.__mouseMoveHandler, this));
+ }
+ },
+
/**
* @methodOf
* @name PanelMenuItem#show
@@ -275,6 +287,22 @@
}
},
+ __contains: function(id, elt) {
+ while (elt) {
+ if (id == elt.id) {
+ return true;
+ }
+
+ elt = elt.parentNode;
+ }
+
+ return false;
+ },
+
+ __isInside: function(elt) {
+ return this.__contains(this.target, elt) || this.__contains(this.id, elt);
+ },
+
destroy: function () {
$super.destroy.call(this);
}
15 years, 2 months
JBoss Rich Faces SVN: r21465 - in trunk: ui/input/ui/src/main/resources/META-INF/resources/org.richfaces and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: pyaschenko
Date: 2011-02-04 13:37:54 -0500 (Fri, 04 Feb 2011)
New Revision: 21465
Modified:
trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar-utils.js
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js
Log:
https://jira.jboss.org/browse/RF-8161
Modified: trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml
===================================================================
--- trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml 2011-02-04 18:31:43 UTC (rev 21464)
+++ trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml 2011-02-04 18:37:54 UTC (rev 21465)
@@ -46,7 +46,7 @@
jointPoint="#{calendarBean.jointPoint}" direction="#{calendarBean.direction}"
locale="#{calendarBean.locale}" popup="#{calendarBean.popup}"
datePattern="#{calendarBean.pattern}"
- dataModel="#{calendarDataModel}"
+
mode="#{calendarBean.mode}"
disabled="false"
cellWidth="24px"
@@ -65,7 +65,7 @@
ondatemouseover="return onEvent.call(this, event);"
firstWeekDay="4"
horizontalOffset="#{calendarBean.horizontalOffset}"
- verticalOffset="#{calendarBean.verticalOffset}" defaultTime="21:22:01" timeZone="#{calendarBean.timeZone}"
+ verticalOffset="#{calendarBean.verticalOffset}" defaultTime="00:00:00" timeZone="#{calendarBean.timeZone}"
valueChangeListener="#{calendarBean.doValueChangeListener}"
currentDataChangeListener="#{calendarBean.doCurrentDataChangeListener}"
onbeforedateselect="myFunction(event)"
@@ -105,8 +105,8 @@
<f:selectItem itemLabel="d/M/yy HH:mm" itemValue="d/M/yy HH:mm" />
<f:selectItem itemLabel="dd/M/yy hh:mm a"
itemValue="dd/M/yy hh:mm a" />
- <f:selectItem itemLabel="dd/M/yy hh:mm:ss"
- itemValue="dd/M/yy hh:mm:ss" />
+ <f:selectItem itemLabel="dd/M/yy HH:mm:ss"
+ itemValue="dd/M/yy HH:mm:ss" />
<f:selectItem itemLabel="d/MMM/y" itemValue="d/MMM/y" />
<f:selectItem itemLabel="MMM d, yyyy" itemValue="MMM d, yyyy" />
</h:selectOneMenu>
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar-utils.js
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar-utils.js 2011-02-04 18:31:43 UTC (rev 21464)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar-utils.js 2011-02-04 18:37:54 UTC (rev 21465)
@@ -79,6 +79,17 @@
i++;
}
},
+
+ createDate: function (yy,mm,dd,h,m,s) {
+ h=h||0; m=m||0; s=s||0;
+ var date = new Date(yy, mm, dd, h, m, s);
+ if (date.getDate()!=dd) {
+ date = new Date(yy, mm);
+ date.setHours(h); date.setMinutes(m); date.setSeconds(s);
+ date.setUTCDate(dd);
+ }
+ return date;
+ },
/* Year:
* y,yy - 00-99
@@ -165,7 +176,7 @@
var addDay = correctYear ? 1 : 0;
var dd = parseInt(match[d],10); if (isNaN(dd) || dd<1 || dd>this.daysInMonth(yy, mm) + addDay) return null;
- var date = new Date(yy, mm, dd);
+ var date;
// time parsing
if (min!=undefined && h!=undefined)
@@ -186,12 +197,14 @@
}
else if (hh<0 || hh>23) return null;
- date.setHours(hh); date.setMinutes(mmin);
+ date = this.createDate(yy, mm, dd, hh, mmin);
if (s!=undefined)
{
sec = parseInt(match[s], 10); if (isNaN(sec) || sec<0 || sec>59) return null;
date.setSeconds(sec);
}
+ } else {
+ date = this.createDate(yy, mm, dd);
}
if (correctYear) {
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2011-02-04 18:31:43 UTC (rev 21464)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2011-02-04 18:37:54 UTC (rev 21465)
@@ -932,7 +932,8 @@
if (this.options.defaultLabel) {
if (!this.isFocused) updateDefaultLabel.call(this, "");
- } else if (baseInput.value!=undefined)
+ }
+ if (baseInput.value)
{
this.__selectDate(baseInput.value, false, {event:e, element:element});
}
@@ -1040,20 +1041,17 @@
},
setupTimeForDate: function (date) {
+ var result = new Date(date);
if (this.selectedDate && (!this.options.resetTimeOnDateSelect ||
(this.selectedDate.getFullYear() == date.getFullYear() &&
this.selectedDate.getMonth() == date.getMonth() &&
this.selectedDate.getDate() == date.getDate())))
{
- date.setHours(this.selectedDate.getHours());
- date.setMinutes(this.selectedDate.getMinutes());
- date.setSeconds(this.selectedDate.getSeconds());
- } else
- {
- date.setHours(this.options.defaultTime.hours);
- date.setMinutes(this.options.defaultTime.minutes);
- date.setSeconds(this.options.defaultTime.seconds);
+ result = rf.calendarUtils.createDate(date.getFullYear(), date.getMonth(), date.getDate(), this.selectedDate.getHours(), this.selectedDate.getMinutes(), this.selectedDate.getSeconds());
+ } else {
+ result = rf.calendarUtils.createDate(date.getFullYear(), date.getMonth(), date.getDate(), this.options.defaultTime.hours, this.options.defaultTime.minutes, this.options.defaultTime.seconds);
}
+ return result;
},
eventCellOnClick: function (e, obj) {
@@ -1061,10 +1059,10 @@
if (daydata.enabled && daydata._month==0)
{
var date=new Date(this.currentDate);
- date.setDate(daydata.day);
+ date.setUTCDate(daydata.day);
if (this.timeType)
{
- this.setupTimeForDate(date);
+ date = this.setupTimeForDate(date);
}
if (this.__selectDate(date,true, {event:e, element:obj}) && !this.options.showApplyButton)
@@ -1080,7 +1078,7 @@
var date = new Date(daydata.date);
if (this.timeType)
{
- this.setupTimeForDate(date);
+ date = this.setupTimeForDate(date);
}
if (this.__selectDate(date, false, {event:e, element:obj}) && !this.options.showApplyButton)
@@ -1557,10 +1555,11 @@
{
var daydata = this.days[parseInt(this.todayCellId.substr(this.DATE_ELEMENT_ID.length),10)];
var today = new Date();
- var date = new Date(today.getFullYear(), today.getMonth(), today.getDate());
+ var date = new Date(today.getFullYear(), today.getMonth());
+ date.setUTCDate(today.getDate());
if (this.timeType)
{
- this.setupTimeForDate(date);
+ date = this.setupTimeForDate(date);
}
if (daydata.enabled && this.__selectDate(date,true) && !this.options.showApplyButton)
{
@@ -1799,7 +1798,7 @@
if (h!=12) h+=12;
}
}
- var date = new Date(this.selectedDate.getFullYear(), this.selectedDate.getMonth(), this.selectedDate.getDate(), h, m, s);
+ var date = rf.calendarUtils.createDate(this.selectedDate.getFullYear(), this.selectedDate.getMonth(), this.selectedDate.getDate(), h, m, s);
if (date-this.selectedDate && this.invokeEvent("beforetimeselect",null, null, date))
{
this.selectedDate = date;
15 years, 2 months
JBoss Rich Faces SVN: r21464 - in trunk: cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib and 11 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2011-02-04 13:31:43 -0500 (Fri, 04 Feb 2011)
New Revision: 21464
Added:
trunk/examples/validator-demo/src/main/java/org/richfaces/example/GraphValidatorBean.java
trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java
Removed:
trunk/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidator.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/NullValidator.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ObjectValidator.java
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/PropertyModel.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java
trunk/examples/validator-demo/src/main/webapp/WEB-INF/faces-config.xml
trunk/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java
trunk/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java
trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java
trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss
Log:
RESOLVED - issue RF-9679: ObjectValidator component
https://issues.jboss.org/browse/RF-9679
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/PropertyModel.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/PropertyModel.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/PropertyModel.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -110,7 +110,7 @@
private String typeForCasting() {
ClassName type = this.property.getType();
- return ClassName.getSimpleName(type.isPrimitive() ? type.getBoxingName() : type.getSimpleName());
+ return type.getSimpleBoxingName();
}
// Model utility methods.
@@ -132,7 +132,7 @@
public String getTypeName() {
ClassName type = this.property.getType();
- return isFromJavaLang(type) ? type.getSimpleName() : type.getName();
+ return type.getSimpleName() ;
}
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -151,7 +151,7 @@
Element tag = createTag(tagModel.getName());
Element converter = tag.addElement("converter");
addDescription(converter, model);
- converter.addElement("converter-id", model.getId().toString());
+ converter.addElement("converter-id").addText(model.getId().toString());
addTagHandler(converter, tagModel);
appendAttributes(tag, model);
}
@@ -184,7 +184,7 @@
Element tag = createTag(tagModel.getName());
Element validator = tag.addElement("validator");
addDescription(validator, model);
- validator.addElement("validator-id", model.getId().toString());
+ validator.addElement("validator-id").addText(model.getId().toString());
addTagHandler(validator, tagModel);
appendAttributes(tag, model);
}
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -33,55 +33,47 @@
* <p class="changed_added_4_0">
* Tthat class represents information about Jsf object class.
* </p>
- *
+ *
* @author asmirnov(a)exadel.com
*/
-public class ClassName implements Serializable,Comparable<ClassName> {
+public class ClassName implements Serializable, Comparable<ClassName> {
private static final long serialVersionUID = -846623207703750456L;
- private static final ImmutableMap<String, String> PRIMITIVE_TYPES =
- ImmutableMap.<String, String>builder()
- .put(boolean.class.getName(), Boolean.class.getName())
- .put(byte.class.getName(), Byte.class.getName())
- .put(char.class.getName(), Character.class.getName())
- .put(short.class.getName(), Short.class.getName())
- .put(int.class.getName(), Integer.class.getName())
- .put(long.class.getName(), Long.class.getName())
- .put(float.class.getName(), Float.class.getName())
- .put(double.class.getName(), Double.class.getName())
- .build();
+ private static final ImmutableMap<String, String> PRIMITIVE_TYPES = ImmutableMap.<String, String> builder()
+ .put(boolean.class.getName(), Boolean.class.getName()).put(byte.class.getName(), Byte.class.getName())
+ .put(char.class.getName(), Character.class.getName()).put(short.class.getName(), Short.class.getName())
+ .put(int.class.getName(), Integer.class.getName()).put(long.class.getName(), Long.class.getName())
+ .put(float.class.getName(), Float.class.getName()).put(double.class.getName(), Double.class.getName()).build();
- private static final ImmutableMap<String, String> DEFAULT_VALUES =
- ImmutableMap.<String, String>builder()
- .put(boolean.class.getName(), "Boolean.FALSE")
- .put(byte.class.getName(), "Byte.MIN_VALUE")
- .put(char.class.getName(), "Character.MIN_VALUE")
- .put(short.class.getName(), "Short.MIN_VALUE")
- .put(int.class.getName(), "Integer.MIN_VALUE")
- .put(long.class.getName(), "Long.MIN_VALUE")
- .put(float.class.getName(), "Float.MIN_VALUE")
- .put(double.class.getName(), "Double.MIN_VALUE")
- .build();
+ private static final ImmutableMap<String, String> DEFAULT_VALUES = ImmutableMap.<String, String> builder()
+ .put(boolean.class.getName(), "Boolean.FALSE").put(byte.class.getName(), "Byte.MIN_VALUE")
+ .put(char.class.getName(), "Character.MIN_VALUE").put(short.class.getName(), "Short.MIN_VALUE")
+ .put(int.class.getName(), "Integer.MIN_VALUE").put(long.class.getName(), "Long.MIN_VALUE")
+ .put(float.class.getName(), "Float.MIN_VALUE").put(double.class.getName(), "Double.MIN_VALUE").build();
private final String boxingClassName;
private final String fullName;
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
*/
private final String name;
private final boolean primitive;
/**
- * <p class="changed_added_4_0">Id parameters for that class</p>
+ * <p class="changed_added_4_0">
+ * Id parameters for that class
+ * </p>
* TODO append type parameters to key.
*/
private String typeParameters;
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @param cl
*/
public ClassName(Class<?> cl) {
@@ -91,7 +83,7 @@
/**
* <p class="changed_added_4_0">
* </p>
- *
+ *
* @param name
*/
public ClassName(String name) {
@@ -105,8 +97,14 @@
int i = name.indexOf('<');
if (i > 0) {
- this.name = name.substring(0, i);
- this.typeParameters = name.substring(i);
+ int closeBracket = name.lastIndexOf('>');
+ if (closeBracket < 0 || closeBracket==name.length()-1) {
+ this.name = name.substring(0, i);
+ this.typeParameters = name.substring(i);
+ } else {
+ this.name = name.substring(0, i)+name.substring(closeBracket+1);
+ this.typeParameters = name.substring(i,closeBracket+1);
+ }
} else {
this.name = name;
}
@@ -117,8 +115,12 @@
}
/**
- * <p class="changed_added_4_0">Factory method to create class names. For empty or null name, returns null</p>
- * @param name fully-cvalified class name
+ * <p class="changed_added_4_0">
+ * Factory method to create class names. For empty or null name, returns null
+ * </p>
+ *
+ * @param name
+ * fully-cvalified class name
* @return new class name instance or null.
*/
public static ClassName parseName(String name) {
@@ -129,7 +131,7 @@
if (name == null) {
return null;
}
-
+
return new ClassName(name);
}
@@ -142,8 +144,9 @@
}
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return the typeParameters
*/
public String getTypeParameters() {
@@ -151,9 +154,11 @@
}
/**
- * <p class="changed_added_4_0"></p>
- *
- * @param typeParameters the typeParameters to set
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param typeParameters
+ * the typeParameters to set
*/
public void setTypeParameters(String typeParameters) {
this.typeParameters = typeParameters;
@@ -162,7 +167,7 @@
/**
* <p class="changed_added_4_0">
* </p>
- *
+ *
* @return the name
*/
public String getName() {
@@ -170,8 +175,9 @@
}
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return package name.
*/
public String getPackage() {
@@ -185,36 +191,51 @@
}
public String getSimpleName() {
- return getSimpleName(name);
- }
-
- public static String getSimpleName(String name) {
int indexOfPeriod = name.lastIndexOf('.');
if (indexOfPeriod > 0) {
- return name.substring(indexOfPeriod + 1);
+ return fullName.substring(indexOfPeriod + 1);
} else {
- return name;
+ return fullName;
}
}
/**
+ * <p class="changed_added_4_0">Return simple name for boxing class: Booilean,Integer etc.</p>
+ * @return
+ */
+ public String getSimpleBoxingName() {
+ if(isPrimitive()){
+ int indexOfPeriod;
+ indexOfPeriod = boxingClassName.lastIndexOf('.');
+ if (indexOfPeriod > 0) {
+ return boxingClassName.substring(indexOfPeriod + 1);
+ } else {
+ return boxingClassName;
+ }
+ } else {
+ return getSimpleName();
+ }
+ }
+
+ /**
* <p class="changed_added_4_0">
* </p>
- *
+ *
* @return the primitive
*/
public boolean isPrimitive() {
return primitive;
}
- public String getDefaultValue(){
+ public String getDefaultValue() {
return DEFAULT_VALUES.get(name);
}
+
/**
* <p class="changed_added_4_0">
* </p>
- *
+ *
* @return the boxingClassName
*/
public String getBoxingName() {
@@ -231,7 +252,8 @@
}
/*
- * (non-Javadoc)
+ * (non-Javadoc)
+ *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -245,7 +267,8 @@
}
/*
- * (non-Javadoc)
+ * (non-Javadoc)
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
Modified: trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java
===================================================================
--- trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -63,7 +63,10 @@
@Parameters
public static Collection<String[]> values() {
return Arrays.asList(new String[] { int.class.getName(), "int", "java.lang.Integer", null, null, "int" },
- new String[] { "java.util.List<String>", "java.util.List", "java.util.List<String>", "<String>","java.util", "List" },
+ new String[] { "java.util.List<String>", "java.util.List", "java.util.List<String>", "<String>","java.util", "List<String>" },
+ new String[] { "java.lang.String[]", "java.lang.String[]", "java.lang.String[]", null, "java.lang", "String[]" },
+ new String[] { "java.util.List<String>[]", "java.util.List[]", "java.util.List<String>[]", "<String>","java.util", "List<String>[]" },
+ new String[] { "java.util.List<java.lang.String>", "java.util.List", "java.util.List<java.lang.String>", "<java.lang.String>","java.util", "List<java.lang.String>" },
new String[] { double.class.getName(), "double", "java.lang.Double", null, null,"double" });
}
Added: trunk/examples/validator-demo/src/main/java/org/richfaces/example/GraphValidatorBean.java
===================================================================
--- trunk/examples/validator-demo/src/main/java/org/richfaces/example/GraphValidatorBean.java (rev 0)
+++ trunk/examples/validator-demo/src/main/java/org/richfaces/example/GraphValidatorBean.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -0,0 +1,103 @@
+/**
+ *
+ */
+package org.richfaces.example;
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+
+
+/**
+ * @author asmirnov
+ *
+ */
+public class GraphValidatorBean implements Cloneable {
+
+ @Min(0)
+ @Max(10)
+ private int first ;
+
+ @Min(0)
+ @Max(10)
+ private int second ;
+ @Min(0)
+ @Max(10)
+ private int third ;
+
+ private String actionResult;
+
+ /**
+ * @return the actionResult
+ */
+ public String getActionResult() {
+ return actionResult;
+ }
+
+ /**
+ * @param actionResult the actionResult to set
+ */
+ public void setActionResult(String actionResult) {
+ this.actionResult = actionResult;
+ }
+
+ /**
+ * @return the first
+ */
+ public int getFirst() {
+ return first;
+ }
+
+ /**
+ * @param first the first to set
+ */
+ public void setFirst(int first) {
+ this.first = first;
+ }
+
+ /**
+ * @return the second
+ */
+ public int getSecond() {
+ return second;
+ }
+
+ /**
+ * @param second the second to set
+ */
+ public void setSecond(int second) {
+ this.second = second;
+ }
+
+ /**
+ * @return the third
+ */
+ public int getThird() {
+ return third;
+ }
+
+ /**
+ * @param third the third to set
+ */
+ public void setThird(int third) {
+ this.third = third;
+ }
+
+ /**
+ * @return total summ of the list values.
+ */
+ @Max(value=20,message="Total value should be less then 20")
+ public int getSumm(){
+ return first+second+third;
+ }
+
+ public String action() {
+ // Persist your data here
+ setActionResult("Data have been saved");
+ return null;
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+}
Property changes on: trunk/examples/validator-demo/src/main/java/org/richfaces/example/GraphValidatorBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/examples/validator-demo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/examples/validator-demo/src/main/webapp/WEB-INF/faces-config.xml 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/examples/validator-demo/src/main/webapp/WEB-INF/faces-config.xml 2011-02-04 18:31:43 UTC (rev 21464)
@@ -7,6 +7,11 @@
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
+ <managed-bean-name>graphValidatorBean</managed-bean-name>
+ <managed-bean-class>org.richfaces.example.GraphValidatorBean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+</managed-bean>
+<managed-bean>
<managed-bean-name>dataBean</managed-bean-name>
<managed-bean-class>org.richfaces.example.DataBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
Modified: trunk/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java
===================================================================
--- trunk/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -161,7 +161,7 @@
@Test
public void testCreateExtendedDataModel() {
Assert.assertFalse(table.createExtendedDataModel() instanceof Arrangeable);
- List<String> sortPriority = Arrays.asList("id2", "id0", "id1");
+ List<Object> sortPriority = Arrays.<Object>asList("id2", "id0", "id1");
List<UIComponent> children = table.getChildren();
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
ELContext elContext = facesContext.getELContext();
@@ -240,8 +240,8 @@
*/
@Test
public void testSortPriority() {
- table.setSortPriority(Collections.EMPTY_LIST);
- Assert.assertEquals(Collections.EMPTY_LIST, table.getSortPriority());
+ table.setSortPriority(Collections.emptyList());
+ Assert.assertEquals(0, table.getSortPriority().size());
}
/**
Modified: trunk/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java
===================================================================
--- trunk/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -21,7 +21,23 @@
*/
Collection<ValidatorDescriptor> getConstrains(FacesContext context, ValueExpression expression,Class<?> ...groups);
-// Collection<String> validateExpression(FacesContext context,ValueExpression expression, Object newValue,Class<?> ...groups);
+ /**
+ * <p class="changed_added_4_0">Validate expression for a new value.</p>
+ * @param context
+ * @param expression
+ * @param newValue
+ * @param groups
+ * @return
+ */
+ Collection<String> validateExpression(FacesContext context,ValueExpression expression, Object newValue,Class<?> ...groups);
-// Collection<String> validateObject(FacesContext context,Object object, Object newValue,Class<?> ...groups);
+ /**
+ * <p class="changed_added_4_0">Validate entire object.</p>
+ * @param context
+ * @param object
+ * @param groups
+ * @return
+ */
+ Collection<String> validateObject(FacesContext context,Object object, Class<?> ...groups);
+
}
Modified: trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java
===================================================================
--- trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -4,7 +4,6 @@
package org.richfaces.validator;
import java.util.Collection;
-import java.util.Set;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -19,6 +18,6 @@
public interface GraphValidator {
public Collection<String> validateGraph(FacesContext context, UIComponent component, Object value,
- Set<String> profiles) throws ValidatorException;
+ Class<?>[] groups) throws ValidatorException;
}
Modified: trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -30,7 +30,6 @@
import org.richfaces.javascript.ClientScriptServiceImpl;
import org.richfaces.javascript.ClientServiceConfigParser;
import org.richfaces.javascript.LibraryFunction;
-import org.richfaces.validator.BeanValidator;
import org.richfaces.validator.BeanValidatorService;
import org.richfaces.validator.BeanValidatorServiceImpl;
import org.richfaces.validator.ConverterServiceImpl;
@@ -39,8 +38,6 @@
import org.richfaces.validator.FacesValidatorService;
import org.richfaces.validator.FacesValidatorServiceImpl;
import org.richfaces.validator.InitializationException;
-import org.richfaces.validator.NullValidator;
-import org.richfaces.validator.ObjectValidator;
import org.richfaces.validator.RichFacesBeanValidatorFactory;
/**
@@ -76,23 +73,18 @@
void configureBeanValidators(ServicesFactory factory){
BeanValidatorService service ;
- ObjectValidator validator;
try {
RichFacesBeanValidatorFactory validatorFactory = new RichFacesBeanValidatorFactory();
validatorFactory.init();
service = new BeanValidatorServiceImpl(new ValueExpressionAnalayserImpl(), validatorFactory);
- validator = new BeanValidator(validatorFactory);
} catch (InitializationException e) {
// JSR-303 is available but not initialised.
service = new DummyBeanValidatorService();
- validator = new NullValidator();
} catch (NoClassDefFoundError e){
// JSR-303 is not avalable.
// log.warn("Validator implementations not found at classpath, default NullValidator will be used.");
service = new DummyBeanValidatorService();
- validator = new NullValidator();
}
factory.setInstance(BeanValidatorService.class, service);
- factory.setInstance(ObjectValidator.class, validator);
}
}
Copied: trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java (from rev 21423, trunk/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java)
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java (rev 0)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -0,0 +1,289 @@
+/**
+ * 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.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.el.CapturingELResolver;
+import org.richfaces.el.ELContextWrapper;
+import org.richfaces.validator.FacesBeanValidator;
+import org.richfaces.validator.GraphValidator;
+import org.richfaces.validator.GraphValidatorState;
+
+/**
+ * JSF component class
+ *
+ */
+@JsfComponent(tag=@Tag(name="graphValidator",type=TagType.Facelets))
+public abstract class AbstractGraphValidator extends UIComponentBase {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.GraphValidator";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.GraphValidator";
+
+ /**
+ * Get object for validation
+ *
+ * @return
+ */
+ @Attribute
+ public abstract Object getValue();
+
+ /**
+ * Set object for validation
+ *
+ * @param newvalue
+ */
+ public abstract void setValue(Object newvalue);
+
+ /**
+ * Get object for validation
+ *
+ * @return
+ */
+ @Attribute
+ public abstract String getSummary();
+
+ /**
+ * Set object for validation
+ *
+ * @param newvalue
+ */
+ public abstract void setSummary(String newvalue);
+
+ /**
+ * Get set of profiles for validation
+ *
+ * @return
+ */
+ @Attribute
+ public abstract Class<?>[] getGroups();
+
+ /**
+ * Set set of profiles for validation
+ *
+ * @param newvalue
+ */
+ public abstract void setGroups(Class<?>[] newvalue);
+
+ /**
+ * Get graph validator Id.
+ *
+ * @return
+ */
+ @Attribute(defaultValue="org.richfaces.BeanValidator")
+ public abstract String getType();
+
+ /**
+ * Set graph validator Id.
+ *
+ * @param newvalue
+ */
+ public abstract void setType(String newvalue);
+
+ @Override
+ public void processDecodes(FacesContext context) {
+ GraphValidatorState validatorState = null;
+ // Detect value EL-expression.
+ ValueExpression valueExpression = getValueExpression("value");
+ if (null != valueExpression) {
+
+ Object value = getValue();
+ if (null != value && value instanceof Cloneable) {
+ try {
+ ELContext initialELContext = context.getELContext();
+
+ CapturingELResolver capturingELResolver = new CapturingELResolver(initialELContext.getELResolver());
+ Class<?> type =
+ valueExpression.getType(new ELContextWrapper(initialELContext, capturingELResolver));
+ if (null != type) {
+ validatorState = new GraphValidatorState();
+ Method method = getCloneMethod(value.getClass());
+ if (!Modifier.isPublic(method.getModifiers())) {
+ // Method Object#clone() is protected by default. Make it public
+ // unless developer did it.
+ method.setAccessible(true);
+ }
+ validatorState.setCloned(method.invoke(value));
+ validatorState.setBase(capturingELResolver.getBase());
+ validatorState.setProperty(capturingELResolver.getProperty());
+ validatorState.setActive(true);
+ context.getExternalContext().getRequestMap().put(getStateId(context), validatorState);
+ }
+ } catch (NoSuchMethodException e) {
+ // do nothing, that is really not possible.
+ } catch (InvocationTargetException e) {
+ throw new FacesException(e);
+ } catch (IllegalArgumentException e) {
+ // do nothing, that is really not possible.
+ } catch (IllegalAccessException e) {
+ throw new FacesException(e);
+ }
+ }
+ }
+ super.processDecodes(context);
+ if (null != validatorState) {
+ validatorState.setActive(false);
+ }
+ }
+
+ private Method getCloneMethod(Class<?> clazz) throws NoSuchMethodException {
+ try {
+ return clazz.getDeclaredMethod("clone");
+ } catch (NoSuchMethodException e) {
+ if (null != clazz.getSuperclass()) {
+ return getCloneMethod(clazz.getSuperclass());
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ protected String getStateId(FacesContext context) {
+ String stateId = GraphValidatorState.STATE_ATTRIBUTE_PREFIX + getClientId(context);
+ return stateId;
+ }
+
+ protected GraphValidatorState getValidatorState(FacesContext context) {
+ return (GraphValidatorState) context.getExternalContext().getRequestMap().get(getStateId(context));
+ }
+
+ @Override
+ public void processValidators(FacesContext context) {
+ GraphValidatorState validatorState = getValidatorState(context);
+ if (null != validatorState) {
+ validatorState.setActive(true);
+ }
+ super.processValidators(context);
+ if (null != validatorState) {
+ validatorState.setActive(false);
+ validateObject(context, validatorState.getCloned());
+ context.getExternalContext().getRequestMap().remove(getStateId(context));
+ }
+ }
+
+ @Override
+ public void processUpdates(FacesContext context) {
+ super.processUpdates(context);
+ Object value = getValue();
+ validateObject(context, value);
+ }
+
+ private void validateObject(FacesContext context, Object value) {
+ if (null != value) {
+ Validator validator = context.getApplication().createValidator(getType());
+ if (validator instanceof GraphValidator) {
+ GraphValidator graphValidator = (GraphValidator) validator;
+ Collection<String> messages = graphValidator.validateGraph(context, this, value, getGroups());
+ if (null != messages) {
+ context.renderResponse();
+ // send all validation messages.
+ String clientId = getClientId(context);
+ for (String msg : messages) {
+ // TODO - create Summary message ?
+ String summary = null != getSummary() ? getSummary() + msg : msg;
+ context.addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, msg));
+ }
+ }
+
+ } else {
+ throw new FacesException("Validator " + FacesBeanValidator.BEAN_VALIDATOR_TYPE
+ + " does not implement GraphValidator");
+ }
+
+ }
+ }
+
+ @Override
+ public void encodeBegin(FacesContext context) throws IOException {
+ super.encodeBegin(context);
+ FacesBeanValidator validator = (FacesBeanValidator) context.getApplication().createValidator(getType());
+ validator.setSummary(getSummary());
+ ValueExpression expression = getValueExpression("groups");
+ if (null != expression) {
+ validator.setGroups(expression);
+ } else {
+ validator.setGroups(getGroups());
+ }
+ setupValidators(this, validator);
+ }
+
+ @Override
+ public void encodeChildren(FacesContext context) throws IOException {
+ if (isRendered()) {
+ for (UIComponent child : getChildren()) {
+ if (child.isRendered()) {
+ child.encodeAll(context);
+ }
+ }
+ }
+ }
+
+ private void setupValidators(UIComponent component, Validator validator) {
+ Iterator<UIComponent> facetsAndChildren = component.getFacetsAndChildren();
+ while (facetsAndChildren.hasNext()) {
+ UIComponent child = facetsAndChildren.next();
+ if (child instanceof EditableValueHolder) {
+ EditableValueHolder input = (EditableValueHolder) child;
+ setupValidator(input, validator);
+ }
+ setupValidators(child, validator);
+ }
+ }
+
+ /**
+ * @param input
+ */
+ private void setupValidator(EditableValueHolder input, Validator validator) {
+ Validator[] validators = input.getValidators();
+ for (int i = 0; i < validators.length; i++) {
+ if (validators[i].getClass().equals(validator.getClass())) {
+ return;
+ }
+ }
+ input.addValidator(validator);
+ }
+
+ @Override
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+}
Deleted: trunk/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -1,281 +0,0 @@
-/**
- * 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.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.el.ELContext;
-import javax.el.ValueExpression;
-import javax.faces.FacesException;
-import javax.faces.application.FacesMessage;
-import javax.faces.component.EditableValueHolder;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.Validator;
-
-import org.richfaces.el.CapturingELResolver;
-import org.richfaces.el.ELContextWrapper;
-import org.richfaces.validator.FacesBeanValidator;
-import org.richfaces.validator.GraphValidator;
-import org.richfaces.validator.GraphValidatorState;
-
-/**
- * JSF component class
- *
- */
-public abstract class UIGraphValidator extends UIComponentBase {
-
- public static final String COMPONENT_TYPE = "org.richfaces.GraphValidator";
-
- public static final String COMPONENT_FAMILY = "org.richfaces.GraphValidator";
-
- /**
- * Get object for validation
- *
- * @return
- */
- public abstract Object getValue();
-
- /**
- * Set object for validation
- *
- * @param newvalue
- */
- public abstract void setValue(Object newvalue);
-
- /**
- * Get object for validation
- *
- * @return
- */
- public abstract String getSummary();
-
- /**
- * Set object for validation
- *
- * @param newvalue
- */
- public abstract void setSummary(String newvalue);
-
- /**
- * Get set of profiles for validation
- *
- * @return
- */
- public abstract Set<String> getProfiles();
-
- /**
- * Set set of profiles for validation
- *
- * @param newvalue
- */
- public abstract void setProfiles(Object newvalue);
-
- /**
- * Get graph validator Id.
- *
- * @return
- */
- public abstract String getType();
-
- /**
- * Set graph validator Id.
- *
- * @param newvalue
- */
- public abstract void setType(String newvalue);
-
- @Override
- public void processDecodes(FacesContext context) {
- GraphValidatorState validatorState = null;
- // Detect value EL-expression.
- ValueExpression valueExpression = getValueExpression("value");
- if (null != valueExpression) {
-
- Object value = getValue();
- if (null != value && value instanceof Cloneable) {
- try {
- ELContext initialELContext = context.getELContext();
-
- CapturingELResolver capturingELResolver = new CapturingELResolver(initialELContext.getELResolver());
- Class<?> type =
- valueExpression.getType(new ELContextWrapper(initialELContext, capturingELResolver));
- if (null != type) {
- validatorState = new GraphValidatorState();
- Method method = getCloneMethod(value.getClass());
- if (!Modifier.isPublic(method.getModifiers())) {
- // Method Object#clone() is protected by default. Make it public
- // unless developer did it.
- method.setAccessible(true);
- }
- validatorState.setCloned(method.invoke(value));
- validatorState.setBase(capturingELResolver.getBase());
- validatorState.setProperty(capturingELResolver.getProperty());
- validatorState.setActive(true);
- context.getExternalContext().getRequestMap().put(getStateId(context), validatorState);
- }
- } catch (NoSuchMethodException e) {
- // do nothing, that is really not possible.
- } catch (InvocationTargetException e) {
- throw new FacesException(e);
- } catch (IllegalArgumentException e) {
- // do nothing, that is really not possible.
- } catch (IllegalAccessException e) {
- throw new FacesException(e);
- }
- }
- }
- super.processDecodes(context);
- if (null != validatorState) {
- validatorState.setActive(false);
- }
- }
-
- private Method getCloneMethod(Class<?> clazz) throws NoSuchMethodException {
- try {
- return clazz.getDeclaredMethod("clone");
- } catch (NoSuchMethodException e) {
- if (null != clazz.getSuperclass()) {
- return getCloneMethod(clazz.getSuperclass());
- } else {
- throw e;
- }
- }
- }
-
- protected String getStateId(FacesContext context) {
- String stateId = GraphValidatorState.STATE_ATTRIBUTE_PREFIX + getClientId(context);
- return stateId;
- }
-
- protected GraphValidatorState getValidatorState(FacesContext context) {
- return (GraphValidatorState) context.getExternalContext().getRequestMap().get(getStateId(context));
- }
-
- @Override
- public void processValidators(FacesContext context) {
- GraphValidatorState validatorState = getValidatorState(context);
- if (null != validatorState) {
- validatorState.setActive(true);
- }
- super.processValidators(context);
- if (null != validatorState) {
- validatorState.setActive(false);
- validateObject(context, validatorState.getCloned());
- context.getExternalContext().getRequestMap().remove(getStateId(context));
- }
- }
-
- @Override
- public void processUpdates(FacesContext context) {
- super.processUpdates(context);
- Object value = getValue();
- validateObject(context, value);
- }
-
- private void validateObject(FacesContext context, Object value) {
- if (null != value) {
- Validator validator = context.getApplication().createValidator(getType());
- if (validator instanceof GraphValidator) {
- GraphValidator graphValidator = (GraphValidator) validator;
- Collection<String> messages = graphValidator.validateGraph(context, this, value, getProfiles());
- if (null != messages) {
- context.renderResponse();
- // send all validation messages.
- String clientId = getClientId(context);
- for (String msg : messages) {
- // TODO - create Summary message ?
- String summary = null != getSummary() ? getSummary() + msg : msg;
- context.addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, msg));
- }
- }
-
- } else {
- throw new FacesException("Validator " + FacesBeanValidator.BEAN_VALIDATOR_TYPE
- + " does not implement GraphValidator");
- }
-
- }
- }
-
- @Override
- public void encodeBegin(FacesContext context) throws IOException {
- super.encodeBegin(context);
- FacesBeanValidator validator = (FacesBeanValidator) context.getApplication().createValidator(getType());
- validator.setSummary(getSummary());
- ValueExpression expression = getValueExpression("profiles");
- if (null != expression) {
- validator.setProfiles(expression);
- } else {
- validator.setProfiles(getProfiles());
- }
- setupValidators(this, validator);
- }
-
- @Override
- public void encodeChildren(FacesContext context) throws IOException {
- if (isRendered()) {
- for (UIComponent child : getChildren()) {
- if (child.isRendered()) {
- child.encodeAll(context);
- }
- }
- }
- }
-
- private void setupValidators(UIComponent component, Validator validator) {
- Iterator<UIComponent> facetsAndChildren = component.getFacetsAndChildren();
- while (facetsAndChildren.hasNext()) {
- UIComponent child = facetsAndChildren.next();
- if (child instanceof EditableValueHolder) {
- EditableValueHolder input = (EditableValueHolder) child;
- setupValidator(input, validator);
- }
- setupValidators(child, validator);
- }
- }
-
- /**
- * @param input
- */
- private void setupValidator(EditableValueHolder input, Validator validator) {
- Validator[] validators = input.getValidators();
- for (int i = 0; i < validators.length; i++) {
- if (validators[i] instanceof FacesBeanValidator) {
- return;
- }
- }
- input.addValidator(validator);
- }
-
- @Override
- public boolean getRendersChildren() {
- return true;
- }
-
-}
Modified: trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -59,6 +59,7 @@
import org.richfaces.renderkit.html.FormClientValidatorRenderer;
import org.richfaces.validator.BeanValidatorService;
import org.richfaces.validator.ConverterDescriptor;
+import org.richfaces.validator.FacesBeanValidator;
import org.richfaces.validator.FacesConverterService;
import org.richfaces.validator.FacesValidatorService;
import org.richfaces.validator.ValidatorDescriptor;
@@ -279,7 +280,7 @@
FacesValidatorService facesValidatorService = ServiceTracker.getService(facesContext,
FacesValidatorService.class);
for (Validator validator : facesValidators) {
- if (validator instanceof BeanValidator) {
+ if (validator instanceof BeanValidator || validator instanceof FacesBeanValidator) {
ValueExpression valueExpression = component.getValueExpression(VALUE);
if (null != valueExpression) {
BeanValidatorService beanValidatorService = ServiceTracker.getService(facesContext,
Deleted: trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidator.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidator.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidator.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -1,112 +0,0 @@
-/**
- *
- */
-package org.richfaces.validator;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Set;
-
-import javax.faces.FacesException;
-import javax.faces.context.FacesContext;
-import javax.validation.ConstraintViolation;
-import javax.validation.Validator;
-import javax.validation.groups.Default;
-
-/**
- * @author asmirnov
- *
- */
-public class BeanValidator extends ObjectValidator {
-
- private static final Class<?>[] DEFAULT_PROFILE = new Class[] {Default.class};
- private final BeanValidatorFactory validatorFactory;
-
-
- public BeanValidator(BeanValidatorFactory validatorFactory) {
- this.validatorFactory = validatorFactory;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.validator.ObjectValidator#validate(java.lang.Object, java.lang.String, java.lang.Object,
- * java.util.Locale)
- */
- @Override
- protected Collection<String> validate(FacesContext facesContext, Object base, String property, Object value,
- Set<String> profiles) {
- @SuppressWarnings("rawtypes")
- Class beanType = base.getClass();
- @SuppressWarnings("unchecked")
- Set<ConstraintViolation<Object>> constrains =
- getValidator(facesContext).validateValue(beanType, property, value, getGroups(profiles));
- return extractMessages(constrains);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.validator.ObjectValidator#validateGraph(javax.faces.context .FacesContext, java.lang.Object,
- * java.util.Set)
- */
- @Override
- public Collection<String> validateGraph(FacesContext context, Object value, Set<String> profiles) {
- Class<?>[] groups = getGroups(profiles);
- Set<ConstraintViolation<Object>> violations = getValidator(context).validate(value, groups);
- Collection<String> messages = extractMessages(violations);
- if (null != parent) {
- Collection<String> parentMessages = parent.validateGraph(context, value, profiles);
- if (null != messages) {
- if (null != parentMessages) {
- messages.addAll(parentMessages);
- }
- } else {
- messages = parentMessages;
- }
- }
- return messages;
- }
-
- private Class<?>[] getGroups(Set<String> profiles) {
- Class<?>[] groups = null;
- if (null != profiles) {
- groups = new Class<?>[profiles.size()];
- int i = 0;
- for (String group : profiles) {
- try {
- groups[i] = Class.forName(group, false, Thread.currentThread().getContextClassLoader());
- } catch (ClassNotFoundException e) {
- try {
- groups[i] = Class.forName(group);
- } catch (ClassNotFoundException e1) {
- throw new FacesException("Bean validation group not found " + group, e1);
- }
- }
- i++;
- }
-
- } else {
- groups = DEFAULT_PROFILE;
- }
- return groups;
- }
-
- private Collection<String> extractMessages(Set<ConstraintViolation<Object>> violations) {
- Collection<String> messages = null;
- if (null != violations && violations.size() > 0) {
- messages = new ArrayList<String>(violations.size());
- for (ConstraintViolation<? extends Object> constraintViolation : violations) {
- messages.add(constraintViolation.getMessage());
- }
-
- }
- return messages;
- }
-
- protected Validator getValidator(FacesContext facesContext) {
- Validator beanValidator = validatorFactory.getValidator(facesContext);
- return beanValidator;
- }
-
-}
Modified: trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -3,23 +3,34 @@
*/
package org.richfaces.validator;
+import java.beans.FeatureDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.EmptyStackException;
import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import java.util.Stack;
+import javax.el.ELContext;
import javax.el.ELException;
+import javax.el.ELResolver;
import javax.el.ValueExpression;
+import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
+import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.metadata.ElementDescriptor.ConstraintFinder;
import javax.validation.metadata.PropertyDescriptor;
+import org.richfaces.el.ELContextWrapper;
import org.richfaces.el.ValueDescriptor;
import org.richfaces.el.ValueExpressionAnalayser;
@@ -32,6 +43,9 @@
public class BeanValidatorServiceImpl implements BeanValidatorService {
private static final Collection<String> HIDDEN_PARAMS = ImmutableSet.of("message","payload","groups");
+ private static final String FACES_CONTEXT_IS_NULL = "Faces context is null";
+ private static final String INPUT_PARAMETERS_IS_NOT_CORRECT = "Input parameters is not correct.";
+ private static final Class<?>[] DEFAULT_GROUP={};
private final ValueExpressionAnalayser analayser;
private final BeanValidatorFactory validatorFactory;
@@ -130,4 +144,321 @@
}
return annotationClass;
}
+
+ public Collection<String> validateExpression(FacesContext context, ValueExpression expression, Object newValue,
+ Class<?>... groups) {
+ if (null == context) {
+ throw new FacesException(INPUT_PARAMETERS_IS_NOT_CORRECT);
+ }
+ Collection<String> validationMessages = Collections.emptySet();
+ if (null != expression) {
+ ELContext elContext = context.getELContext();
+ ValidationResolver validationResolver =
+ createValidationResolver(context, elContext.getELResolver(), groups);
+ ELContextWrapper wrappedElContext = new ELContextWrapper(elContext, validationResolver);
+ try {
+ expression.setValue(wrappedElContext, newValue);
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+ if (!validationResolver.isValid()) {
+ validationMessages = validationResolver.getValidationMessages();
+ }
+ }
+ return validationMessages;
+ }
+
+
+ protected ValidationResolver createValidationResolver(FacesContext context, ELResolver parent, Class<?>[] groups) {
+ return new ValidationResolver(parent, context, groups);
+ }
+
+ /**
+ * @author asmirnov
+ *
+ */
+ protected static class BasePropertyPair {
+ private final Object base;
+ private final Object property;
+
+ /**
+ * @param base
+ * @param property
+ */
+ public BasePropertyPair(Object base, Object property) {
+ this.base = base;
+ this.property = property;
+ }
+
+ /**
+ * @return the base
+ */
+ public Object getBase() {
+ return base;
+ }
+
+ /**
+ * @return the property
+ */
+ public Object getProperty() {
+ return property;
+ }
+
+ }
+
+ /**
+ * Class for identify validator instance by locale
+ *
+ * @author amarkhel
+ *
+ */
+ protected static class ValidatorKey {
+ private final Class<? extends Object> validatableClass;
+ private final Locale locale;
+
+ /**
+ * Constructor for ValidatorKey object
+ *
+ * @param validatableClass
+ * - class to validate
+ * @param locale
+ * - User locale to determine Resource bundle, used during validation process
+ */
+ public ValidatorKey(Class<? extends Object> validatableClass, Locale locale) {
+ this.validatableClass = validatableClass;
+ this.locale = locale;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((this.locale == null) ? 0 : this.locale.hashCode());
+ result = prime * result + ((this.validatableClass == null) ? 0 : this.validatableClass.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ValidatorKey other = (ValidatorKey) obj;
+ if (this.locale == null) {
+ if (other.locale != null) {
+ return false;
+ }
+ } else if (!this.locale.equals(other.locale)) {
+ return false;
+ }
+ if (this.validatableClass == null) {
+ if (other.validatableClass != null) {
+ return false;
+ }
+ } else if (!this.validatableClass.equals(other.validatableClass)) {
+ return false;
+ }
+ return true;
+ }
+
+
+
+ }
+
+ /**
+ * Wrapper class for a {@link ELResolver}. For a setValue method, perform validation instead of real assignment.
+ *
+ * @author asmirnov
+ *
+ */
+ final class ValidationResolver extends ELResolver {
+
+ /**
+ * Original resolver.
+ */
+ private final ELResolver parent;
+
+ private boolean valid = true;
+
+ private Collection<String> validationMessages = null;
+
+ private Stack<BasePropertyPair> valuesStack;
+
+ private Class<?>[] groups;
+
+ private FacesContext facesContext;
+
+ private boolean clonedObject = false;
+
+ /**
+ * @param parent
+ * @param context
+ */
+ public ValidationResolver(ELResolver parent, FacesContext context, Class<?>[] groups) {
+ this.parent = parent;
+ this.valuesStack = new Stack<BasePropertyPair>();
+ this.groups = groups;
+ this.facesContext = context;
+ }
+
+ public boolean isValid() {
+ return valid;
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @return
+ * @see javax.el.ELResolver#getCommonPropertyType(javax.el.ELContext, java.lang.Object)
+ */
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ return parent.getCommonPropertyType(context, base);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @return
+ * @see javax.el.ELResolver#getFeatureDescriptors(javax.el.ELContext, java.lang.Object)
+ */
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
+ return parent.getFeatureDescriptors(context, base);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @return
+ * @see javax.el.ELResolver#getType(javax.el.ELContext, java.lang.Object, java.lang.Object)
+ */
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ return parent.getType(context, base, property);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @return
+ * @see javax.el.ELResolver#getValue(javax.el.ELContext, java.lang.Object, java.lang.Object)
+ */
+ public Object getValue(ELContext context, Object base, Object property) {
+ Object value = ClonedObjectResolver.resolveCloned(context, base, property);
+ if (null != value) {
+ this.clonedObject = true;
+ context.setPropertyResolved(true);
+ } else {
+ value = parent.getValue(context, base, property);
+ }
+ valuesStack.push(new BasePropertyPair(base, property));
+ return value;
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @return
+ * @see javax.el.ELResolver#isReadOnly(javax.el.ELContext, java.lang.Object, java.lang.Object)
+ */
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ return parent.isReadOnly(context, base, property);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @param value
+ * @see javax.el.ELResolver#setValue(javax.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object)
+ */
+ public void setValue(ELContext context, Object base, Object property, Object value) {
+ if (null != base && null != property) {
+ // TODO - detect value object from inderect references ( e.g. data table variables ).
+ if (this.clonedObject) {
+ parent.setValue(context, base, property, value);
+ }
+ context.setPropertyResolved(true);
+ // For Arrays, Collection or Map use parent base and property.
+ BasePropertyPair basePropertyPair = lookupBeanProperty(new BasePropertyPair(base, property));
+ base = basePropertyPair.getBase();
+ property = basePropertyPair.getProperty();
+ if (null != base && null != property) {
+ // https://jira.jboss.org/jira/browse/RF-4034
+ // apache el looses locale information during value
+ // resolution,
+ // so we use our own
+ validationMessages = validate(facesContext, base, property.toString(), value, groups);
+ valid = null == validationMessages || 0 == validationMessages.size();
+
+ }
+ }
+ }
+
+ private BasePropertyPair lookupBeanProperty(BasePropertyPair pair) {
+ Object base = pair.getBase();
+ if (null != base && (base instanceof Collection || base instanceof Map || base.getClass().isArray())) {
+ try {
+ pair = lookupBeanProperty(valuesStack.pop());
+ } catch (EmptyStackException e) {
+ // Do nothing, this is a first item.
+ }
+ }
+ return pair;
+ }
+
+ /**
+ * @return the validationMessages
+ */
+ public Collection<String> getValidationMessages() {
+ return validationMessages;
+ }
+
+ }
+
+ protected Collection<String> validate(FacesContext facesContext, Object base, String property, Object value,
+ Class<?>[] groups) {
+ @SuppressWarnings("rawtypes")
+ Class beanType = base.getClass();
+ @SuppressWarnings("unchecked")
+ Set<ConstraintViolation<Object>> constrains =
+ getValidator(facesContext).validateValue(beanType, property, value, getGroups(groups));
+ return extractMessages(constrains);
+ }
+
+ private Class<?>[] getGroups(Class<?>[] groups) {
+ return null==groups?DEFAULT_GROUP:groups;
+ }
+
+ public Collection<String> validateObject(FacesContext context, Object value, Class<?>... groups) {
+ Set<ConstraintViolation<Object>> violations = getValidator(context).validate(value, getGroups(groups));
+ Collection<String> messages = extractMessages(violations);
+ return messages;
+ }
+
+ private Collection<String> extractMessages(Set<ConstraintViolation<Object>> violations) {
+ Collection<String> messages = null;
+ if (null != violations && violations.size() > 0) {
+ messages = new ArrayList<String>(violations.size());
+ for (ConstraintViolation<? extends Object> constraintViolation : violations) {
+ messages.add(constraintViolation.getMessage());
+ }
+
+ }
+ return messages;
+ }
+
}
Modified: trunk/ui/validator/ui/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -23,4 +23,13 @@
return Collections.emptySet();
}
+ public Collection<String> validateExpression(FacesContext context, ValueExpression expression, Object newValue,
+ Class<?>... groups) {
+ return Collections.emptySet();
+ }
+
+ public Collection<String> validateObject(FacesContext context, Object object, Class<?>... groups) {
+ return Collections.emptySet();
+ }
+
}
Modified: trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -24,7 +24,6 @@
import java.text.MessageFormat;
import java.util.Collection;
import java.util.Locale;
-import java.util.Set;
import javax.el.ELException;
import javax.el.ValueExpression;
@@ -36,12 +35,20 @@
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.cdk.annotations.JsfValidator;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+
+import com.google.common.base.Strings;
+
/**
* Implementation of the JSF validator to use with Bean Validation / Hibernate validator
*
* @author asmirnov
*
*/
+@JsfValidator(id=FacesBeanValidator.BEAN_VALIDATOR_TYPE,tag=(a)Tag(name="beanValidator",type=TagType.Facelets))
public class FacesBeanValidator implements Serializable, Validator, GraphValidator {
public static final String BEAN_VALIDATOR_TYPE = "org.richfaces.BeanValidator";
@@ -53,10 +60,14 @@
private String summary = null;
- private ValueExpression profilesExpression = null;
+ private ValueExpression groupsExpression = null;
- private Set<String> profiles = null;
+ private Class<?>[] groups = null;
+ private BeanValidatorService validatorService;
+ public FacesBeanValidator() {
+ this.validatorService = ServiceTracker.getService(BeanValidatorService.class);
+ }
/**
* @return the summary
*/
@@ -100,9 +111,9 @@
ValueExpression valueExpression = component.getValueExpression("value");
if (null != valueExpression) {
Collection<String> messages =
- ObjectValidator.getInstance(context).validate(context, valueExpression, convertedValue,
- getProfiles());
- if (null != messages) {
+ validatorService.validateExpression(context, valueExpression, convertedValue,
+ getGroups());
+ if (!messages.isEmpty()) {
input.setValid(false);
Object label = getLabel(context, component);
Locale locale = context.getViewRoot().getLocale();
@@ -111,10 +122,10 @@
// https://jira.jboss.org/jira/browse/RF-7636 -
// format values.
String formattedMessage = formatMessage(msg, locale, label, convertedValue); // create Summary message ?
- String summaryString = getSummary() != null ? getSummary() : formattedMessage;
- summaryString = formatMessage(summaryString, locale, label, convertedValue);
+ String summary = getSummary();
+ String formattedSummary = Strings.isNullOrEmpty(summary) ? formattedMessage:formatMessage(summary, locale, label, convertedValue);
context.addMessage(component.getClientId(context), new FacesMessage(
- FacesMessage.SEVERITY_ERROR, summaryString, formattedMessage));
+ FacesMessage.SEVERITY_ERROR, formattedSummary, formattedMessage));
}
}
}
@@ -145,21 +156,20 @@
}
public Collection<String> validateGraph(FacesContext context, UIComponent component, Object value,
- Set<String> profiles) throws ValidatorException {
- ObjectValidator beanValidator = ObjectValidator.getInstance(context);
- Collection<String> messages = beanValidator.validateGraph(context, value, profiles);
+ Class<?>[] groups) throws ValidatorException {
+ Collection<String> messages = validatorService.validateObject(context, value, groups);
return messages;
}
/**
* @return the profiles
*/
- public Set<String> getProfiles() {
- Set<String> profiles;
- if (null != profilesExpression) {
- profiles = (Set<String>) profilesExpression.getValue(FacesContext.getCurrentInstance().getELContext());
+ public Class<?>[] getGroups() {
+ Class<?>[] profiles;
+ if (null != groupsExpression) {
+ profiles = (Class<?>[]) groupsExpression.getValue(FacesContext.getCurrentInstance().getELContext());
} else {
- profiles = this.profiles;
+ profiles = this.groups;
}
return profiles;
}
@@ -168,11 +178,11 @@
* @param profiles
* the profiles to set
*/
- public void setProfiles(Set<String> profiles) {
- this.profiles = profiles;
+ public void setGroups(Class<?>... profiles) {
+ this.groups = profiles;
}
- public void setProfiles(ValueExpression profilesExpression) {
- this.profilesExpression = profilesExpression;
+ public void setGroups(ValueExpression profilesExpression) {
+ this.groupsExpression = profilesExpression;
}
}
\ No newline at end of file
Deleted: trunk/ui/validator/ui/src/main/java/org/richfaces/validator/NullValidator.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/validator/NullValidator.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/validator/NullValidator.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -1,42 +0,0 @@
-/**
- *
- */
-package org.richfaces.validator;
-
-import java.util.Collection;
-import java.util.Set;
-
-import javax.faces.context.FacesContext;
-
-/**
- * @author asmirnov
- *
- */
-public class NullValidator extends ObjectValidator {
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.validator.ObjectValidator#validate(java.lang.Object, java.lang.String, java.lang.Object,
- * java.util.Locale)
- */
- @Override
- protected Collection<String> validate(FacesContext facesContext, Object base, String property, Object value,
- Set<String> profiles) {
- // do nothing.
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.validator.ObjectValidator#validateGraph(javax.faces.context.FacesContext, java.lang.Object,
- * java.util.Set)
- */
- @Override
- public Collection<String> validateGraph(FacesContext context, Object value, Set<String> profiles) {
- // do nothing
- return null;
- }
-
-}
Deleted: trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ObjectValidator.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ObjectValidator.java 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ObjectValidator.java 2011-02-04 18:31:43 UTC (rev 21464)
@@ -1,420 +0,0 @@
-package org.richfaces.validator;
-
-import java.beans.FeatureDescriptor;
-import java.util.Collection;
-import java.util.EmptyStackException;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.Stack;
-
-import javax.el.ELContext;
-import javax.el.ELException;
-import javax.el.ELResolver;
-import javax.el.ValueExpression;
-import javax.faces.FacesException;
-import javax.faces.application.Application;
-import javax.faces.context.FacesContext;
-
-import org.richfaces.application.ServiceTracker;
-import org.richfaces.el.ELContextWrapper;
-
-public abstract class ObjectValidator {
-
- private static final String RESOURCE_BUNDLE_IS_NOT_REGISTERED_FOR_CURRENT_LOCALE =
- "Resource bundle is not registered for current locale";
-
- private static final String FACES_CONTEXT_IS_NULL = "Faces context is null";
- private static final String INPUT_PARAMETERS_IS_NOT_CORRECT = "Input parameters is not correct.";
- private static final String LOCALE_IS_NOT_SET = "Locale is not set";
- private static final String VIEW_ROOT_IS_NOT_INITIALIZED = "ViewRoot is not initialized";
-
- protected final ObjectValidator parent;
-
- ObjectValidator() {
- this.parent = null;
- }
-
- ObjectValidator(ObjectValidator parent) {
- this.parent = parent;
- }
-
- /**
- * Return BeanValidator object from a ServletContext attribute. Create new instance if none is defined.
- *
- * @param context
- * @return
- */
- public static ObjectValidator getInstance(FacesContext context) {
- return ServiceTracker.getService(context, ObjectValidator.class);
- }
-
- public abstract Collection<String> validateGraph(FacesContext context, Object value, Set<String> profiles);
-
- /**
- * Perform Validation for a new value.
- *
- * @param context
- * current faces context.
- * @param target
- * {@link ValueExpression} for a value assignment.
- * @param value
- * new value for validation
- * @param profiles
- * TODO
- * @return null if no validation errors. Array of the validation messages otherwise.
- * @throws FacesException
- * if locale or context not properly initialized
- */
- public Collection<String> validate(FacesContext context, ValueExpression target, Object value, Set<String> profiles) {
- if (null == context) {
- throw new FacesException(INPUT_PARAMETERS_IS_NOT_CORRECT);
- }
- Collection<String> validationMessages = null;
- if (null != target) {
- ELContext elContext = context.getELContext();
- ValidationResolver validationResolver =
- createValidationResolver(context, elContext.getELResolver(), profiles);
- ELContextWrapper wrappedElContext = new ELContextWrapper(elContext, validationResolver);
- try {
- target.setValue(wrappedElContext, value);
- } catch (ELException e) {
- throw new FacesException(e);
- }
- if (!validationResolver.isValid()) {
- validationMessages = validationResolver.getValidationMessages();
- }
- if (null != parent) {
- Collection<String> parentMessages = parent.validate(context, target, value, profiles);
- if (null != validationMessages) {
- if (null != parentMessages) {
- validationMessages.addAll(parentMessages);
- }
- } else {
- validationMessages = parentMessages;
- }
- }
-
- }
- return validationMessages;
- }
-
- /**
- * Validate bean property for a new value.
- *
- * @param facesContext
- * TODO
- * @param base
- * - bean
- * @param property
- * - bean property name.
- * @param value
- * new value.
- * @param profiles
- * TODO
- *
- * @return null for a valid value, array of the validation messages othervise.
- */
- protected abstract Collection<String> validate(FacesContext facesContext, Object base, String property,
- Object value, Set<String> profiles);
-
- static Locale calculateLocale(FacesContext context) {
- if (null == context.getViewRoot()) {
- throw new FacesException(VIEW_ROOT_IS_NOT_INITIALIZED);
- } else if (null == context.getViewRoot().getLocale()) {
- throw new FacesException(LOCALE_IS_NOT_SET);
- }
- Locale locale = context.getViewRoot().getLocale();
- return locale;
- }
-
- static ResourceBundle getResourceBundle(FacesContext facesContext, String name) {
- ResourceBundle bundle = null;
- if (null != facesContext) {
- Application application = facesContext.getApplication();
- try {
- bundle = application.getResourceBundle(facesContext, name);
-
- } catch (Exception e) {
- // Let one more attempt to load resource
- }
- }
- if (null == bundle) {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- if (null == classLoader) {
- classLoader = ObjectValidator.class.getClassLoader();
- }
- try {
- bundle = ResourceBundle.getBundle(name, calculateLocale(facesContext), classLoader);
-
- } catch (MissingResourceException e) {
- // Do nothing, use default bundle.
- }
- }
- return bundle;
- }
-
- protected ValidationResolver createValidationResolver(FacesContext context, ELResolver parent, Set<String> profiles) {
- return new ValidationResolver(parent, context, profiles);
- }
-
- /**
- * @author asmirnov
- *
- */
- protected static class BasePropertyPair {
- private final Object base;
- private final Object property;
-
- /**
- * @param base
- * @param property
- */
- public BasePropertyPair(Object base, Object property) {
- this.base = base;
- this.property = property;
- }
-
- /**
- * @return the base
- */
- public Object getBase() {
- return base;
- }
-
- /**
- * @return the property
- */
- public Object getProperty() {
- return property;
- }
-
- }
-
- /**
- * Class for identify validator instance by locale
- *
- * @author amarkhel
- *
- */
- protected static class ValidatorKey {
- private final Class<? extends Object> validatableClass;
- private final Locale locale;
-
- /**
- * Constructor for ValidatorKey object
- *
- * @param validatableClass
- * - class to validate
- * @param locale
- * - User locale to determine Resource bundle, used during validation process
- */
- public ValidatorKey(Class<? extends Object> validatableClass, Locale locale) {
- this.validatableClass = validatableClass;
- this.locale = locale;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((this.locale == null) ? 0 : this.locale.hashCode());
- result = prime * result + ((this.validatableClass == null) ? 0 : this.validatableClass.hashCode());
- return result;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- ValidatorKey other = (ValidatorKey) obj;
- if (this.locale == null) {
- if (other.locale != null) {
- return false;
- }
- } else if (!this.locale.equals(other.locale)) {
- return false;
- }
- if (this.validatableClass == null) {
- if (other.validatableClass != null) {
- return false;
- }
- } else if (!this.validatableClass.equals(other.validatableClass)) {
- return false;
- }
- return true;
- }
-
-
-
- }
-
- /**
- * Wrapper class for a {@link ELResolver}. For a setValue method, perform validation instead of real assignment.
- *
- * @author asmirnov
- *
- */
- final class ValidationResolver extends ELResolver {
-
- /**
- * Original resolver.
- */
- private final ELResolver parent;
-
- private boolean valid = true;
-
- private Collection<String> validationMessages = null;
-
- private Stack<BasePropertyPair> valuesStack;
-
- private Set<String> profiles;
-
- private FacesContext facesContext;
-
- private boolean clonedObject = false;
-
- /**
- * @param parent
- * @param context
- */
- public ValidationResolver(ELResolver parent, FacesContext context, Set<String> profiles) {
- this.parent = parent;
- this.valuesStack = new Stack<BasePropertyPair>();
- this.profiles = profiles;
- this.facesContext = context;
- }
-
- public boolean isValid() {
- return valid;
- }
-
- /**
- * @param context
- * @param base
- * @return
- * @see javax.el.ELResolver#getCommonPropertyType(javax.el.ELContext, java.lang.Object)
- */
- public Class<?> getCommonPropertyType(ELContext context, Object base) {
- return parent.getCommonPropertyType(context, base);
- }
-
- /**
- * @param context
- * @param base
- * @return
- * @see javax.el.ELResolver#getFeatureDescriptors(javax.el.ELContext, java.lang.Object)
- */
- public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
- return parent.getFeatureDescriptors(context, base);
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @return
- * @see javax.el.ELResolver#getType(javax.el.ELContext, java.lang.Object, java.lang.Object)
- */
- public Class<?> getType(ELContext context, Object base, Object property) {
- return parent.getType(context, base, property);
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @return
- * @see javax.el.ELResolver#getValue(javax.el.ELContext, java.lang.Object, java.lang.Object)
- */
- public Object getValue(ELContext context, Object base, Object property) {
- Object value = ClonedObjectResolver.resolveCloned(context, base, property);
- if (null != value) {
- this.clonedObject = true;
- context.setPropertyResolved(true);
- } else {
- value = parent.getValue(context, base, property);
- }
- valuesStack.push(new BasePropertyPair(base, property));
- return value;
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @return
- * @see javax.el.ELResolver#isReadOnly(javax.el.ELContext, java.lang.Object, java.lang.Object)
- */
- public boolean isReadOnly(ELContext context, Object base, Object property) {
- return parent.isReadOnly(context, base, property);
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @param value
- * @see javax.el.ELResolver#setValue(javax.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object)
- */
- public void setValue(ELContext context, Object base, Object property, Object value) {
- if (null != base && null != property) {
- // TODO - detect value object from inderect references ( e.g. data table variables ).
- if (this.clonedObject) {
- parent.setValue(context, base, property, value);
- }
- context.setPropertyResolved(true);
- // For Arrays, Collection or Map use parent base and property.
- BasePropertyPair basePropertyPair = lookupBeanProperty(new BasePropertyPair(base, property));
- base = basePropertyPair.getBase();
- property = basePropertyPair.getProperty();
- if (null != base && null != property) {
- // https://jira.jboss.org/jira/browse/RF-4034
- // apache el looses locale information during value
- // resolution,
- // so we use our own
- validationMessages = validate(facesContext, base, property.toString(), value, profiles);
- valid = null == validationMessages || 0 == validationMessages.size();
-
- }
- }
- }
-
- private BasePropertyPair lookupBeanProperty(BasePropertyPair pair) {
- Object base = pair.getBase();
- if (null != base && (base instanceof Collection || base instanceof Map || base.getClass().isArray())) {
- try {
- pair = lookupBeanProperty(valuesStack.pop());
- } catch (EmptyStackException e) {
- // Do nothing, this is a first item.
- }
- }
- return pair;
- }
-
- /**
- * @return the validationMessages
- */
- public Collection<String> getValidationMessages() {
- return validationMessages;
- }
-
- }
-
-}
\ No newline at end of file
Modified: trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss
===================================================================
--- trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss 2011-02-04 17:59:50 UTC (rev 21463)
+++ trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss 2011-02-04 18:31:43 UTC (rev 21464)
@@ -5,7 +5,7 @@
height:18ex;
}
/* all messages */
-.rf-msg-err, rf-msg-ftl, rf-msg-inf, rf-msg-wrn {
+.rf-msg-err, .rf-msg-ftl, .rf-msg-inf, .rf-msg-wrn {
display:inline-block;
padding-right:2px;
padding-left:20px;
15 years, 2 months