Author: pyaschenko
Date: 2010-11-25 09:19:25 -0500 (Thu, 25 Nov 2010)
New Revision: 20170
Added:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/regex-validator.js
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/RegexValidatorTest.java
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/double-range-validator.js
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/long-range-validator.js
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/DoubleRangeValidatorTest.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/LongRangeValidatorTest.java
Log:
http://jira.jboss.com/jira/browse/RF-9329
RegexValidator and tests was added
bugfix
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/double-range-validator.js
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/double-range-validator.js 2010-11-25
13:11:20 UTC (rev 20169)
+++
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/double-range-validator.js 2010-11-25
14:19:25 UTC (rev 20170)
@@ -2,12 +2,17 @@
(function(rf) {
return function (componentId, value, params) {
- if (typeof value == "string") {
- value = $.trim(value);
+ var type = typeof value;
+ if (type != "number") {
+ if (type != "string") {
+ throw rf.csv.getMessage(params.customMessage, 'DOUBLE_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
+ } else {
+ value = $.trim(value);
+ if (!rf.csv.RE_FLOAT.test(value) || (value = parseFloat(value))==NaN) {
+ throw rf.csv.getMessage(params.customMessage,
'DOUBLE_RANGE_VALIDATOR_TYPE', [componentId, ""]);
+ }
+ }
}
- if (!rf.csv.RE_FLOAT.test(value) || (value = parseFloat(value))==NaN) {
- throw rf.csv.getMessage(params.customMessage, 'DOUBLE_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
- }
var isMinSet = typeof params.minimum == "number";
var isMaxSet = typeof params.maximum == "number";
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/long-range-validator.js
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/long-range-validator.js 2010-11-25
13:11:20 UTC (rev 20169)
+++
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/long-range-validator.js 2010-11-25
14:19:25 UTC (rev 20170)
@@ -2,12 +2,17 @@
(function(rf) {
return function (componentId, value, params) {
- if (typeof value == "string") {
- value = $.trim(value);
+ var type = typeof value;
+ if (type != "number") {
+ if (type != "string") {
+ throw rf.csv.getMessage(params.customMessage, 'LONG_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
+ } else {
+ value = $.trim(value);
+ if (!rf.csv.RE_DIGITS.test(value) || (value = parseInt(value, 10))==NaN) {
+ throw rf.csv.getMessage(params.customMessage, 'LONG_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
+ }
+ }
}
- if (!rf.csv.RE_DIGITS.test(value)) {
- throw rf.csv.getMessage(params.customMessage, 'LONG_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
- }
var isMinSet = typeof params.minimum == "number";
var isMaxSet = typeof params.maximum == "number";
Added:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/regex-validator.js
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/regex-validator.js
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/regex-validator.js 2010-11-25
14:19:25 UTC (rev 20170)
@@ -0,0 +1,20 @@
+RichFaces.csv.addValidator({"regex":
+ (function(rf) {
+ return function (componentId, value, params) {
+
+ if (typeof params.pattern != "string" || params.pattern.length == 0) {
+ throw rf.csv.getMessage(params.customMessage,
'REGEX_VALIDATOR_PATTERN_NOT_SET', []);
+ }
+
+ var re;
+ try {
+ re = new RegExp(params.pattern);
+ } catch (e) {
+ throw rf.csv.getMessage(params.customMessage,
'REGEX_VALIDATOR_MATCH_EXCEPTION', []);
+ }
+ if (!re.test(value)){
+ throw rf.csv.getMessage(params.customMessage, 'REGEX_VALIDATOR_NOT_MATCHED',
[params.pattern]);
+ }
+ }
+ })(window.RichFaces || (window.RichFaces={}))
+});
\ No newline at end of file
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/DoubleRangeValidatorTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/DoubleRangeValidatorTest.java 2010-11-25
13:11:20 UTC (rev 20169)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/DoubleRangeValidatorTest.java 2010-11-25
14:19:25 UTC (rev 20170)
@@ -69,7 +69,7 @@
successes = {
@TestData(submittedValue = "0.9"),
@TestData(submittedValue = "1.1"),
- @TestData(submittedValue = "1.2"),
+ @TestData(submittedValue = "1.2")
},
failures = {
@TestData(submittedValue = "1.3"),
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/LongRangeValidatorTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/LongRangeValidatorTest.java 2010-11-25
13:11:20 UTC (rev 20169)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/LongRangeValidatorTest.java 2010-11-25
14:19:25 UTC (rev 20170)
@@ -51,7 +51,7 @@
successes = {
@TestData(submittedValue = "5"),
@TestData(submittedValue = "7"),
- @TestData(submittedValue = "10"),
+ @TestData(submittedValue = "10")
},
failures = {
@TestData(submittedValue = "4"),
Added:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/RegexValidatorTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/RegexValidatorTest.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/RegexValidatorTest.java 2010-11-25
14:19:25 UTC (rev 20170)
@@ -0,0 +1,80 @@
+/*
+ * 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.validator.RegexValidator;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.appplication.FacesMessages;
+
+/**
+ * @author Pavel Yaschenko
+ *
+ */
+(a)RunWith(ValidatorTestRunner.class)
+public class RegexValidatorTest extends BaseTest {
+
+ private Enum<?>[] messages = { FacesMessages.REGEX_VALIDATOR_MATCH_EXCEPTION,
FacesMessages.REGEX_VALIDATOR_NOT_MATCHED,
FacesMessages.REGEX_VALIDATOR_PATTERN_NOT_SET};
+
+ private void setup() {
+ setClientFunction("RichFaces.csv.getValidator('regex')");
+ setObjectId(RegexValidator.VALIDATOR_ID);
+ setErrorMessageEnums(messages);
+ }
+
+ public RegexValidatorTest() {
+ super("META-INF/resources/org.richfaces/regex-validator.js");
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ @TestData(submittedValue = "hello Man!!!"),
+ @TestData(submittedValue = "say hello"),
+ @TestData(submittedValue = "--- hello ---")
+ },
+ failures = {
+ @TestData(submittedValue = "foo-foo-foo"),
+ @TestData(submittedValue = "")
+ }
+ )
+
+ public void test() throws Exception {
+ setup();
+ setAttribute("pattern", "hello");
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ },
+ failures = {
+ @TestData(submittedValue = "text")
+ }
+ )
+
+ public void wrongPatternTest() throws Exception {
+ setup();
+ setAttribute("pattern", "((");
+ }
+}