Author: alexsmirnov
Date: 2010-11-05 16:16:25 -0400 (Fri, 05 Nov 2010)
New Revision: 19975
Added:
trunk/ui/validator/.checkstyle
trunk/ui/validator/impl/src/test/java/org/richfaces/validator/CustomGroup.java
Modified:
trunk/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
trunk/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
Log:
RESOLVED - issue RF-9631: rich:validator doesn't work with JSR-303 restrictions
without 'groups' attribute set.
https://jira.jboss.org/browse/RF-9631
Added: trunk/ui/validator/.checkstyle
===================================================================
--- trunk/ui/validator/.checkstyle (rev 0)
+++ trunk/ui/validator/.checkstyle 2010-11-05 20:16:25 UTC (rev 19975)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<fileset-config file-format-version="1.2.0" simple-config="false"
sync-formatter="false">
+ <fileset name="all" enabled="true"
check-config-name="RichFaces" local="false">
+ <file-match-pattern match-pattern="src/main/.*\.java"
include-pattern="true"/>
+ </fileset>
+ <filter name="NonSrcDirs" enabled="true"/>
+</fileset-config>
Modified:
trunk/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
===================================================================
---
trunk/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2010-11-05
19:05:34 UTC (rev 19974)
+++
trunk/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2010-11-05
20:16:25 UTC (rev 19975)
@@ -16,6 +16,7 @@
import javax.faces.context.FacesContext;
import javax.validation.Validator;
import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.ElementDescriptor.ConstraintFinder;
import javax.validation.metadata.PropertyDescriptor;
import org.richfaces.el.ValueDescriptor;
@@ -57,11 +58,16 @@
Collection<ValidatorDescriptor> processBeanAttribute(FacesContext context,
ValueDescriptor descriptor,
Class<?>... groups) {
- PropertyDescriptor constraintsForProperty =
getValidator(context).getConstraintsForClass(
- descriptor.getBeanType()).getConstraintsForProperty(descriptor.getName());
+ PropertyDescriptor constraintsForProperty =
+
getValidator(context).getConstraintsForClass(descriptor.getBeanType()).getConstraintsForProperty(
+ descriptor.getName());
if (null != constraintsForProperty) {
- Set<ConstraintDescriptor<?>> constraints =
constraintsForProperty.findConstraints()
- .unorderedAndMatchingGroups(groups) // or the requested list of groups)
+ ConstraintFinder propertyConstraints =
constraintsForProperty.findConstraints();
+ if (null != groups && groups.length > 0) {
+ // Filter groups, if required
+ propertyConstraints =
propertyConstraints.unorderedAndMatchingGroups(groups);
+ }
+ Set<ConstraintDescriptor<?>> constraints = propertyConstraints //
or the requested list of groups)
.getConstraintDescriptors();
// ContextHolder is an arbitrary object, it will depend on the
implementation
Modified:
trunk/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java
===================================================================
---
trunk/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java 2010-11-05
19:05:34 UTC (rev 19974)
+++
trunk/ui/validator/impl/src/test/java/org/richfaces/validator/BeanValidatorServiceConstrainsTest.java 2010-11-05
20:16:25 UTC (rev 19975)
@@ -12,6 +12,7 @@
import javax.el.ValueExpression;
import javax.faces.component.UIViewRoot;
import javax.validation.constraints.Size;
+import javax.validation.groups.Default;
import org.jboss.test.faces.mock.Environment;
import org.jboss.test.faces.mock.Environment.Feature;
@@ -77,7 +78,7 @@
@Test
public void testValidatorMessageExtractor() throws Exception {
forProperty(Bean.class, "string");
- Collection<ValidatorDescriptor> validators = expectValidators(Size.class);
+ Collection<ValidatorDescriptor> validators = expectValidators(
Size.class);
ValidatorDescriptor validatorDescriptor = Iterables.getOnlyElement(validators);
assertEquals("size must be between 0 and
2",validatorDescriptor.getMessage().getSummary());
}
@@ -92,9 +93,16 @@
assertTrue(validatorDescriptor.getAdditionalParameters().containsKey(param));
assertEquals(value, validatorDescriptor.getAdditionalParameters().get(param));
}
+
+ /**
+ */
private Collection<ValidatorDescriptor> expectValidators(Class<? extends
Annotation>... validators) {
+ return expectValidatorsWithGroups(new Class<?>[0], validators);
+ }
+
+ private Collection<ValidatorDescriptor>
expectValidatorsWithGroups(Class<?>[] groups, Class<? extends Annotation>...
validators) {
controller.replay();
- Collection<ValidatorDescriptor> constrains =
validatorService.getConstrains(environment.getFacesContext(), expression);
+ Collection<ValidatorDescriptor> constrains =
validatorService.getConstrains(environment.getFacesContext(), expression,groups);
controller.verify();
assertEquals(validators.length, constrains.size());
for (final Class<? extends Annotation> class1 : validators) {
@@ -107,4 +115,18 @@
}
return constrains;
}
+
+ @Test
+ public void testGetConstrainsWithDefaulGroup() throws Exception {
+ forProperty(Bean.class, "string");expectValidatorsWithGroups(new
Class<?>[]{Default.class},Size.class);
+ }
+ @Test
+ public void testGetConstrainsWithNullGroup() throws Exception {
+ forProperty(Bean.class,
"string");expectValidatorsWithGroups(null,Size.class);
+ }
+ @Test
+ public void testGetConstrainsWithCustomGroup() throws Exception {
+ forProperty(Bean.class, "string");expectValidatorsWithGroups(new
Class<?>[]{CustomGroup.class});
+ }
+
}
Added: trunk/ui/validator/impl/src/test/java/org/richfaces/validator/CustomGroup.java
===================================================================
--- trunk/ui/validator/impl/src/test/java/org/richfaces/validator/CustomGroup.java
(rev 0)
+++
trunk/ui/validator/impl/src/test/java/org/richfaces/validator/CustomGroup.java 2010-11-05
20:16:25 UTC (rev 19975)
@@ -0,0 +1,33 @@
+/*
+ * $Id$
+ * 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.validator;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface CustomGroup {
+
+}
Property changes on:
trunk/ui/validator/impl/src/test/java/org/richfaces/validator/CustomGroup.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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 2010-11-05
19:05:34 UTC (rev 19974)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2010-11-05
20:16:25 UTC (rev 19975)
@@ -71,6 +71,8 @@
public class ClientValidatorImpl extends AjaxBehavior implements ClientValidatorBehavior
{
+ private static final Class<?>[] EMPTY_GROUPS = new Class<?>[0];
+
private static final String VALUE = "value";
private static final Logger LOG = RichfacesLogger.COMPONENTS.getLogger();
@@ -297,7 +299,7 @@
FacesContext ctx = FacesContext.getCurrentInstance();
return (Class<?>[]) expression.getValue(ctx.getELContext());
}
- return null;
+ return EMPTY_GROUPS;
}
public void setGroups(Class<?>... groups) {