Author: alexsmirnov
Date: 2011-02-01 19:08:05 -0500 (Tue, 01 Feb 2011)
New Revision: 21379
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientServiceConfigParser.java
trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/ServiceConfigParserTest.java
Log:
RESOLVED - issue RF-10309: CSV: not working JSF validators.
https://issues.jboss.org/browse/RF-10309
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientServiceConfigParser.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientServiceConfigParser.java 2011-02-01
19:12:04 UTC (rev 21378)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/javascript/ClientServiceConfigParser.java 2011-02-02
00:08:05 UTC (rev 21379)
@@ -12,6 +12,8 @@
import javax.faces.FacesException;
import javax.xml.bind.JAXB;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
import org.richfaces.resource.ResourceKey;
import org.richfaces.validator.model.ClientSideScripts;
import org.richfaces.validator.model.Component;
@@ -29,6 +31,8 @@
*/
public final class ClientServiceConfigParser {
+ private static final Logger LOG = RichfacesLogger.CONFIG.getLogger();
+
private ClientServiceConfigParser() {
}
@@ -55,22 +59,26 @@
try {
ClientSideScripts clientSideScripts = JAXB.unmarshal(url,
ClientSideScripts.class);
for (Component component : clientSideScripts.getComponent()) {
- Class<?> componentClass = loader.loadClass(component.getType());
- Iterable<ResourceKey> resources =
Iterables.transform(component.getResource(), new Function<Resource,ResourceKey>(){
+ try {
+ Class<?> componentClass =
loader.loadClass(component.getType());
+ Iterable<ResourceKey> resources =
+ Iterables.transform(component.getResource(), new
Function<Resource, ResourceKey>() {
- public ResourceKey apply(Resource from) {
- return ResourceKey.create(from.getName(),from.getLibrary());
- }
-
- });
- LibraryFunctionImplementation function = new
LibraryFunctionImplementation(component.getFunction(),
- resources);
- result.put(componentClass, function);
+ public ResourceKey apply(Resource from) {
+ return ResourceKey.create(from.getName(),
from.getLibrary());
+ }
+
+ });
+ LibraryFunctionImplementation function =
+ new LibraryFunctionImplementation(component.getFunction(),
resources);
+ result.put(componentClass, function);
+ } catch (ClassNotFoundException e) {
+ // throw new FacesException("Class for component not
found", e);
+ LOG.warn("Found JavaScript function definition for class
"+component.getType()+", but that class is not presented");
+ }
}
- } catch (ClassNotFoundException e) {
- throw new FacesException("Class for component not found",e);
} catch (Exception e) {
- throw new FacesException("Error parsing config file "+url,e);
+ throw new FacesException("Error parsing config file " + url, e);
}
return result;
}
Modified: trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml
===================================================================
--- trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml 2011-02-01 19:12:04 UTC (rev
21378)
+++ trunk/ui/validator/ui/src/main/resources/META-INF/csv.xml 2011-02-02 00:08:05 UTC (rev
21379)
@@ -33,6 +33,62 @@
<function>RichFaces.csv.convertShort</function>
</component>
<component>
+ <type>javax.faces.convert.CharacterConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertCharacter</function>
+ </component>
+ <component>
+ <type>javax.faces.convert.IntegerConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertInteger</function>
+ </component>
+ <component>
+ <type>javax.faces.convert.LongConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertLong</function>
+ </component>
+ <component>
+ <type>javax.faces.convert.FloatConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertFloat</function>
+ </component>
+ <component>
+ <type>javax.faces.convert.DoubleConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertDouble</function>
+ </component>
+ <component>
+ <type>javax.faces.convert.DateConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertDate</function>
+ </component>
+ <component>
+ <type>javax.faces.convert.ShortConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertShort</function>
+ </component>
+ <component>
<type>javax.faces.validator.LengthValidator</type>
<resource>
<name>csv.reslib</name>
Modified:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-02-01
19:12:04 UTC (rev 21378)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-02-02
00:08:05 UTC (rev 21379)
@@ -22,15 +22,6 @@
}
}
- var _interpolateFacesMessage = function(msg,id,value){
- var d = msg.detail?_substitute(msg.detail,id,value):"";
- var s = msg.summary?_substitute(msg.summary,id,value):"";
- return {detail:d,summary:s};
- }
-
- var _substitute = function(msg,id,value){
- return msg.replace("{id}",id).replace("{value}",value);
- }
var __getValue = function(id) {
var value;
@@ -45,6 +36,7 @@
return value;
}
+
$.extend(rf.csv, {
RE_DIGITS: /^-?\d+$/,
RE_FLOAT: /^(-?\d+)?(\.(\d+)?(e[+-]?\d+)?)?$/,
@@ -103,29 +95,27 @@
}
return true;
},
- /*
- function form_3Atext_3Av(clientId,element,event,disableAjax){var
value=RichFaces.csv.getValue(clientId,element);
- try {
- var convertedValue=value;
- RichFaces.csv.validateLength(convertedValue,{"detail":"{2}: Validation
Error: Specified attribute is not between the expected values of {0} and
{1}.","severity":0,"summary":"{2}: Validation Error:
Specified attribute is not between the expected values of {0} and {1}."}
,{"minimum":1,"maximum":3} );
- if(!disableAjax){
- RichFaces.csv.clearMessage(clientId);
- }
- return true;
- } catch(e) {
- RichFaces.csv.sendMessage(clientId,e);
- return false;
- }}
- */
- /*
- * c: {name:, params:}
- v: [{f:, customMessage:, [validator params]}]
- function form_3Atext_3Av(id, el, e, c, v, p) {
- RichFaces.csv.validate(e, id, el, c, v, p);
- }
- */
});
+ /* convert all natural number formats
+ *
+ */
+ var _convertNatural = function(value,label,msg,min,max,sample){
+ var result; value = $.trim(value);
+ if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<min ||
result>max) {
+ throw rf.csv.interpolateMessage(msg, sample?[value, sample, label]:[value,label]);
+ }
+ return result;
+ }
+
+ var _convertReal = function(value,label,msg,sample){
+ var result; value = $.trim(value);
+ if (!rf.csv.RE_FLOAT.test(value) || isNaN(result=parseFloat(value)) ) {
+ // TODO - check Float limits.
+ throw rf.csv.interpolateMessage(msg, sample?[value, sample, label]:[value,label]);
+ }
+ return result;
+ }
/*
* Converters implementation
*/
@@ -136,13 +126,15 @@
return result;
},
- "convertByte": function (value,label,params,msg) {
+ "convertDate": function (value,label,params,msg) {
var result; value = $.trim(value);
- if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-128 ||
result>127) {
- throw rf.csv.interpolateMessage(msg, [value, 254, label]);
- }
+ // TODO - JSF date converter options.
+ result=Date.parse(value);
return result;
},
+ "convertByte": function (value,label,params,msg) {
+ return _convertNatural(value,label,msg,-128,127,254);
+ },
"convertNumber": function (value,label,params,msg) {
var result; value=$.trim(value);
result = parseFloat(value);
@@ -151,12 +143,23 @@
}
return result;
},
+ "convertFloat": function (value,label,params,msg) {
+ return _convertReal(value,label,msg,2000000000);
+ },
+ "convertDouble": function (value,label,params,msg) {
+ return _convertReal(value,label,msg,1999999);
+ },
"convertShort": function (value,label,params,msg) {
- var result; value = $.trim(value);
- if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-32768 ||
result>32767) {
- throw rf.csv.interpolateMessage(msg, [value, 32456, label]);
- }
- return result;
+ return _convertNatural(value,label,msg,-32768,32767,32456);
+ },
+ "convertInteger": function (value,label,params,msg) {
+ return _convertNatural(value,label,msg, -2147483648,2147483648,9346);
+ },
+ "convertCharacter": function (value,label,params,msg) {
+ return _convertNatural(value,label,msg, 0,65535);
+ },
+ "convertLong": function (value,label,params,msg) {
+ return _convertNatural(value,label,msg,
-9223372036854775808,9223372036854775807,98765432);
}
});
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/ServiceConfigParserTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/ServiceConfigParserTest.java 2011-02-01
19:12:04 UTC (rev 21378)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/ServiceConfigParserTest.java 2011-02-02
00:08:05 UTC (rev 21379)
@@ -8,6 +8,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.richfaces.resource.ResourceKey;
@@ -36,9 +37,11 @@
}
@Test(expected=FacesException.class)
+ @Ignore("parser log errors instead of exception")
public void testParseBadConfig() {
Map<Class<?>, LibraryFunction> parseConfig =
ClientServiceConfigParser.parseConfig("badcsv.xml");
}
+
@Test()
public void testParseNoConfig() {
Map<Class<?>, LibraryFunction> parseConfig =
ClientServiceConfigParser.parseConfig("non-exists-csv.xml");