Author: pyaschenko
Date: 2010-11-25 10:28:35 -0500 (Thu, 25 Nov 2010)
New Revision: 20171
Added:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/required-validator.js
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/RequiredValidatorTest.java
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java
Log:
http://jira.jboss.com/jira/browse/RF-9329
RequiredValidator and tests was added
Added:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/required-validator.js
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/required-validator.js
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/required-validator.js 2010-11-25
15:28:35 UTC (rev 20171)
@@ -0,0 +1,9 @@
+RichFaces.csv.addValidator({"required":
+ (function(rf) {
+ return function (componentId, value, params) {
+ if (value.length==0) {
+ throw rf.csv.getMessage(params.customMessage, 'UIINPUT_REQUIRED',
[componentId]);
+ }
+ }
+ })(window.RichFaces || (window.RichFaces={}))
+});
\ No newline at end of file
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java 2010-11-25
14:19:25 UTC (rev 20170)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java 2010-11-25
15:28:35 UTC (rev 20171)
@@ -199,6 +199,9 @@
HtmlInputText testComponent = new HtmlInputText();
testComponent.setLabel(TEST_COMPONENT_LABEL);
testBean.componentLabel = TEST_COMPONENT_LABEL;
+ if (errorMessage!=null) {
+ testComponent.setRequiredMessage(errorMessage);
+ }
return testComponent;
}
Added:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/RequiredValidatorTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/RequiredValidatorTest.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/RequiredValidatorTest.java 2010-11-25
15:28:35 UTC (rev 20171)
@@ -0,0 +1,76 @@
+/*
+ * 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.RequiredValidator;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.appplication.FacesMessages;
+
+/**
+ * @author Pavel Yaschenko
+ *
+ */
+(a)RunWith(ValidatorTestRunner.class)
+public class RequiredValidatorTest extends BaseTest {
+
+ private Enum<?>[] messages = { FacesMessages.UIINPUT_REQUIRED };
+
+ private void setup() {
+ setClientFunction("RichFaces.csv.getValidator('required')");
+ setObjectId(RequiredValidator.VALIDATOR_ID);
+ setErrorMessageEnums(messages);
+ }
+
+ public RequiredValidatorTest() {
+ super("META-INF/resources/org.richfaces/required-validator.js");
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ @TestData(submittedValue = "foo")
+ },
+ failures = {
+ @TestData(submittedValue = "")
+ }
+ )
+
+ public void test() throws Exception {
+ setup();
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ },
+ failures = {
+ @TestData(submittedValue = "")
+ }
+ )
+
+ public void customMessageTest() throws Exception {
+ setup();
+ setErrorMessage("Input message: value is required");
+ }
+}