Author: pyaschenko
Date: 2010-10-27 13:52:44 -0400 (Wed, 27 Oct 2010)
New Revision: 19710
Added:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/boolean-converter.js
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BooleanConverterTest.java
Modified:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/byte-converter.js
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/number-converter.js
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/short-converter.js
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ByteConverterTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ShortConverterTest.java
Log:
https://jira.jboss.org/browse/RF-9521https://jira.jboss.org/browse/RF-9521
boolean converter was added
+some fixes
Added:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/boolean-converter.js
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/boolean-converter.js
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/boolean-converter.js 2010-10-27
17:52:44 UTC (rev 19710)
@@ -0,0 +1,10 @@
+RichFaces.csv.addConverter({"boolean":
+(function($, rf) {
+ return function (value, params) {
+ var result; value = $.trim(value).toLowerCase();
+ result = value=='true' ? true : value.length<1 ? null : false;
+
+ return result;
+ }
+})(jQuery, window.RichFaces || (window.RichFaces={}))
+});
\ No newline at end of file
Modified:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/byte-converter.js
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/byte-converter.js 2010-10-27
16:56:42 UTC (rev 19709)
+++
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/byte-converter.js 2010-10-27
17:52:44 UTC (rev 19710)
@@ -1,11 +1,11 @@
RichFaces.csv.addConverter({"byte":
-(function(rf) {
+(function($, rf) {
return function (value, params) {
- var result = parseInt(value);
- if (isNaN(result) || result<-128 || result>127) {
+ var result; value = $.trim(value);
+ if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-128 ||
result>127) {
throw rf.csv.getMessage(params.customMessage, 'BYTE_CONVERTER_BYTE', [value,
0, params.componentId]);
}
return result;
}
-})(window.RichFaces || (window.RichFaces={}))
+})(jQuery, window.RichFaces || (window.RichFaces={}))
});
\ No newline at end of file
Modified:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/number-converter.js
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/number-converter.js 2010-10-27
16:56:42 UTC (rev 19709)
+++
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/number-converter.js 2010-10-27
17:52:44 UTC (rev 19710)
@@ -1,7 +1,7 @@
RichFaces.csv.addConverter({"number":
-(function(rf) {
+(function($, rf) {
return function (value, params) {
- var result;
+ var result; value=$.trim(value);
if (isNaN(value)) {
throw rf.csv.getMessage(params.customMessage, 'NUMBER_CONVERTER_NUMBER',
[value, 0, params.componentId]);
} else {
@@ -9,5 +9,5 @@
}
return result;
}
-})(window.RichFaces || (window.RichFaces={}))
+})(jQuery, window.RichFaces || (window.RichFaces={}))
});
\ No newline at end of file
Modified:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2010-10-27
16:56:42 UTC (rev 19709)
+++
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2010-10-27
17:52:44 UTC (rev 19710)
@@ -9,6 +9,7 @@
var RE_MESSAGE_PATTERN = /\{(\d+)\}/g;
$.extend(rf.csv, {
+ RE_DIGITS: /^-?\d+$/,
MESSAGE_EVENT_NAME: "onmessage."+rf.Event.RICH_NAMESPACE,
// Messages API
addMessage: function (messagesObject) {
Modified:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/short-converter.js
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/short-converter.js 2010-10-27
16:56:42 UTC (rev 19709)
+++
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/short-converter.js 2010-10-27
17:52:44 UTC (rev 19710)
@@ -1,11 +1,11 @@
-RichFaces.csv.addConverter({"byte":
-(function(rf) {
+RichFaces.csv.addConverter({"short":
+(function($, rf) {
return function (value, params) {
- var result = parseInt(value);
- if (isNaN(result) || result<-32768 || result>32767) {
+ var result; value = $.trim(value);
+ if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-32768 ||
result>32767) {
throw rf.csv.getMessage(params.customMessage, 'SHORT_CONVERTER_SHORT', [value,
0, params.componentId]);
}
return result;
}
-})(window.RichFaces || (window.RichFaces={}))
+})(jQuery, window.RichFaces || (window.RichFaces={}))
});
\ No newline at end of file
Added:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BooleanConverterTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BooleanConverterTest.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BooleanConverterTest.java 2010-10-27
17:52:44 UTC (rev 19710)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.convert;
+
+import javax.faces.convert.BooleanConverter;
+
+import org.junit.Test;
+import org.richfaces.appplication.FacesMessages;
+
+/**
+ * @author Pavel Yaschenko
+ *
+ */
+public class BooleanConverterTest extends BaseConverterTest {
+
+ public BooleanConverterTest() {
+ super("META-INF/resources/org.richfaces/boolean-converter.js");
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ @TestData(submittedValue = "true"),
+ @TestData(submittedValue = "True"),
+ @TestData(submittedValue = "TRUE"),
+ @TestData(submittedValue = "false"),
+ @TestData(submittedValue = "0"),
+ @TestData(submittedValue = "1"),
+ @TestData(submittedValue = "")
+ },
+ failures = {}
+ )
+ public void testSuccess() throws Exception {
+
setClientConverterClassName("RichFaces.csv.getConverter('boolean')");
+ setConverterId(BooleanConverter.CONVERTER_ID);
+ setConversionErrorMessageEnum(FacesMessages.BOOLEAN_CONVERTER_BOOLEAN);
+ }
+}
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ByteConverterTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ByteConverterTest.java 2010-10-27
16:56:42 UTC (rev 19709)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ByteConverterTest.java 2010-10-27
17:52:44 UTC (rev 19710)
@@ -46,7 +46,11 @@
failures = {
@TestData(submittedValue = "-129"),
@TestData(submittedValue = "128"),
- @TestData(submittedValue = "aaa")
+ @TestData(submittedValue = "1.0"),
+ @TestData(submittedValue = "1.2"),
+ @TestData(submittedValue = "1a"),
+ @TestData(submittedValue = "aaa"),
+ @TestData(submittedValue = "- 127")
}
)
public void testSuccess() throws Exception {
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ShortConverterTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ShortConverterTest.java 2010-10-27
16:56:42 UTC (rev 19709)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ShortConverterTest.java 2010-10-27
17:52:44 UTC (rev 19710)
@@ -46,11 +46,15 @@
failures = {
@TestData(submittedValue = "-32769"),
@TestData(submittedValue = "32768"),
- @TestData(submittedValue = "aaa")
+ @TestData(submittedValue = "1.0"),
+ @TestData(submittedValue = "1.2"),
+ @TestData(submittedValue = "1a"),
+ @TestData(submittedValue = "aaa"),
+ @TestData(submittedValue = "- 10")
}
)
public void testSuccess() throws Exception {
-
setClientConverterClassName("RichFaces.csv.getConverter('byte')");
+
setClientConverterClassName("RichFaces.csv.getConverter('short')");
setConverterId(ShortConverter.CONVERTER_ID);
setConversionErrorMessageEnum(FacesMessages.SHORT_CONVERTER_SHORT);
}