Author: alexsmirnov
Date: 2011-02-04 13:31:43 -0500 (Fri, 04 Feb 2011)
New Revision: 21464
Added:
trunk/examples/validator-demo/src/main/java/org/richfaces/example/GraphValidatorBean.java
trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java
Removed:
trunk/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidator.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/NullValidator.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ObjectValidator.java
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/PropertyModel.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java
trunk/examples/validator-demo/src/main/webapp/WEB-INF/faces-config.xml
trunk/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java
trunk/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java
trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java
trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss
Log:
RESOLVED - issue RF-9679: ObjectValidator component
https://issues.jboss.org/browse/RF-9679
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/PropertyModel.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/PropertyModel.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/freemarker/PropertyModel.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -110,7 +110,7 @@
private String typeForCasting() {
ClassName type = this.property.getType();
- return ClassName.getSimpleName(type.isPrimitive() ? type.getBoxingName() :
type.getSimpleName());
+ return type.getSimpleBoxingName();
}
// Model utility methods.
@@ -132,7 +132,7 @@
public String getTypeName() {
ClassName type = this.property.getType();
- return isFromJavaLang(type) ? type.getSimpleName() : type.getName();
+ return type.getSimpleName() ;
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -151,7 +151,7 @@
Element tag = createTag(tagModel.getName());
Element converter = tag.addElement("converter");
addDescription(converter, model);
- converter.addElement("converter-id",
model.getId().toString());
+
converter.addElement("converter-id").addText(model.getId().toString());
addTagHandler(converter, tagModel);
appendAttributes(tag, model);
}
@@ -184,7 +184,7 @@
Element tag = createTag(tagModel.getName());
Element validator = tag.addElement("validator");
addDescription(validator, model);
- validator.addElement("validator-id",
model.getId().toString());
+
validator.addElement("validator-id").addText(model.getId().toString());
addTagHandler(validator, tagModel);
appendAttributes(tag, model);
}
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java 2011-02-04
17:59:50 UTC (rev 21463)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ClassName.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -33,55 +33,47 @@
* <p class="changed_added_4_0">
* Tthat class represents information about Jsf object class.
* </p>
- *
+ *
* @author asmirnov(a)exadel.com
*/
-public class ClassName implements Serializable,Comparable<ClassName> {
+public class ClassName implements Serializable, Comparable<ClassName> {
private static final long serialVersionUID = -846623207703750456L;
- private static final ImmutableMap<String, String> PRIMITIVE_TYPES =
- ImmutableMap.<String, String>builder()
- .put(boolean.class.getName(), Boolean.class.getName())
- .put(byte.class.getName(), Byte.class.getName())
- .put(char.class.getName(), Character.class.getName())
- .put(short.class.getName(), Short.class.getName())
- .put(int.class.getName(), Integer.class.getName())
- .put(long.class.getName(), Long.class.getName())
- .put(float.class.getName(), Float.class.getName())
- .put(double.class.getName(), Double.class.getName())
- .build();
+ private static final ImmutableMap<String, String> PRIMITIVE_TYPES =
ImmutableMap.<String, String> builder()
+ .put(boolean.class.getName(), Boolean.class.getName()).put(byte.class.getName(),
Byte.class.getName())
+ .put(char.class.getName(), Character.class.getName()).put(short.class.getName(),
Short.class.getName())
+ .put(int.class.getName(), Integer.class.getName()).put(long.class.getName(),
Long.class.getName())
+ .put(float.class.getName(), Float.class.getName()).put(double.class.getName(),
Double.class.getName()).build();
- private static final ImmutableMap<String, String> DEFAULT_VALUES =
- ImmutableMap.<String, String>builder()
- .put(boolean.class.getName(), "Boolean.FALSE")
- .put(byte.class.getName(), "Byte.MIN_VALUE")
- .put(char.class.getName(), "Character.MIN_VALUE")
- .put(short.class.getName(), "Short.MIN_VALUE")
- .put(int.class.getName(), "Integer.MIN_VALUE")
- .put(long.class.getName(), "Long.MIN_VALUE")
- .put(float.class.getName(), "Float.MIN_VALUE")
- .put(double.class.getName(), "Double.MIN_VALUE")
- .build();
+ private static final ImmutableMap<String, String> DEFAULT_VALUES =
ImmutableMap.<String, String> builder()
+ .put(boolean.class.getName(),
"Boolean.FALSE").put(byte.class.getName(), "Byte.MIN_VALUE")
+ .put(char.class.getName(),
"Character.MIN_VALUE").put(short.class.getName(), "Short.MIN_VALUE")
+ .put(int.class.getName(),
"Integer.MIN_VALUE").put(long.class.getName(), "Long.MIN_VALUE")
+ .put(float.class.getName(),
"Float.MIN_VALUE").put(double.class.getName(),
"Double.MIN_VALUE").build();
private final String boxingClassName;
private final String fullName;
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
*/
private final String name;
private final boolean primitive;
/**
- * <p class="changed_added_4_0">Id parameters for that
class</p>
+ * <p class="changed_added_4_0">
+ * Id parameters for that class
+ * </p>
* TODO append type parameters to key.
*/
private String typeParameters;
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @param cl
*/
public ClassName(Class<?> cl) {
@@ -91,7 +83,7 @@
/**
* <p class="changed_added_4_0">
* </p>
- *
+ *
* @param name
*/
public ClassName(String name) {
@@ -105,8 +97,14 @@
int i = name.indexOf('<');
if (i > 0) {
- this.name = name.substring(0, i);
- this.typeParameters = name.substring(i);
+ int closeBracket = name.lastIndexOf('>');
+ if (closeBracket < 0 || closeBracket==name.length()-1) {
+ this.name = name.substring(0, i);
+ this.typeParameters = name.substring(i);
+ } else {
+ this.name = name.substring(0, i)+name.substring(closeBracket+1);
+ this.typeParameters = name.substring(i,closeBracket+1);
+ }
} else {
this.name = name;
}
@@ -117,8 +115,12 @@
}
/**
- * <p class="changed_added_4_0">Factory method to create class names.
For empty or null name, returns null</p>
- * @param name fully-cvalified class name
+ * <p class="changed_added_4_0">
+ * Factory method to create class names. For empty or null name, returns null
+ * </p>
+ *
+ * @param name
+ * fully-cvalified class name
* @return new class name instance or null.
*/
public static ClassName parseName(String name) {
@@ -129,7 +131,7 @@
if (name == null) {
return null;
}
-
+
return new ClassName(name);
}
@@ -142,8 +144,9 @@
}
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return the typeParameters
*/
public String getTypeParameters() {
@@ -151,9 +154,11 @@
}
/**
- * <p class="changed_added_4_0"></p>
- *
- * @param typeParameters the typeParameters to set
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param typeParameters
+ * the typeParameters to set
*/
public void setTypeParameters(String typeParameters) {
this.typeParameters = typeParameters;
@@ -162,7 +167,7 @@
/**
* <p class="changed_added_4_0">
* </p>
- *
+ *
* @return the name
*/
public String getName() {
@@ -170,8 +175,9 @@
}
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return package name.
*/
public String getPackage() {
@@ -185,36 +191,51 @@
}
public String getSimpleName() {
- return getSimpleName(name);
- }
-
- public static String getSimpleName(String name) {
int indexOfPeriod = name.lastIndexOf('.');
if (indexOfPeriod > 0) {
- return name.substring(indexOfPeriod + 1);
+ return fullName.substring(indexOfPeriod + 1);
} else {
- return name;
+ return fullName;
}
}
/**
+ * <p class="changed_added_4_0">Return simple name for boxing class:
Booilean,Integer etc.</p>
+ * @return
+ */
+ public String getSimpleBoxingName() {
+ if(isPrimitive()){
+ int indexOfPeriod;
+ indexOfPeriod = boxingClassName.lastIndexOf('.');
+ if (indexOfPeriod > 0) {
+ return boxingClassName.substring(indexOfPeriod + 1);
+ } else {
+ return boxingClassName;
+ }
+ } else {
+ return getSimpleName();
+ }
+ }
+
+ /**
* <p class="changed_added_4_0">
* </p>
- *
+ *
* @return the primitive
*/
public boolean isPrimitive() {
return primitive;
}
- public String getDefaultValue(){
+ public String getDefaultValue() {
return DEFAULT_VALUES.get(name);
}
+
/**
* <p class="changed_added_4_0">
* </p>
- *
+ *
* @return the boxingClassName
*/
public String getBoxingName() {
@@ -231,7 +252,8 @@
}
/*
- * (non-Javadoc)
+ * (non-Javadoc)
+ *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -245,7 +267,8 @@
}
/*
- * (non-Javadoc)
+ * (non-Javadoc)
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -63,7 +63,10 @@
@Parameters
public static Collection<String[]> values() {
return Arrays.asList(new String[] { int.class.getName(), "int",
"java.lang.Integer", null, null, "int" },
- new String[] { "java.util.List<String>",
"java.util.List", "java.util.List<String>",
"<String>","java.util", "List" },
+ new String[] { "java.util.List<String>",
"java.util.List", "java.util.List<String>",
"<String>","java.util", "List<String>" },
+ new String[] { "java.lang.String[]",
"java.lang.String[]", "java.lang.String[]", null,
"java.lang", "String[]" },
+ new String[] { "java.util.List<String>[]",
"java.util.List[]", "java.util.List<String>[]",
"<String>","java.util", "List<String>[]" },
+ new String[] { "java.util.List<java.lang.String>",
"java.util.List", "java.util.List<java.lang.String>",
"<java.lang.String>","java.util",
"List<java.lang.String>" },
new String[] { double.class.getName(), "double",
"java.lang.Double", null, null,"double" });
}
Added:
trunk/examples/validator-demo/src/main/java/org/richfaces/example/GraphValidatorBean.java
===================================================================
---
trunk/examples/validator-demo/src/main/java/org/richfaces/example/GraphValidatorBean.java
(rev 0)
+++
trunk/examples/validator-demo/src/main/java/org/richfaces/example/GraphValidatorBean.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -0,0 +1,103 @@
+/**
+ *
+ */
+package org.richfaces.example;
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+
+
+/**
+ * @author asmirnov
+ *
+ */
+public class GraphValidatorBean implements Cloneable {
+
+ @Min(0)
+ @Max(10)
+ private int first ;
+
+ @Min(0)
+ @Max(10)
+ private int second ;
+ @Min(0)
+ @Max(10)
+ private int third ;
+
+ private String actionResult;
+
+ /**
+ * @return the actionResult
+ */
+ public String getActionResult() {
+ return actionResult;
+ }
+
+ /**
+ * @param actionResult the actionResult to set
+ */
+ public void setActionResult(String actionResult) {
+ this.actionResult = actionResult;
+ }
+
+ /**
+ * @return the first
+ */
+ public int getFirst() {
+ return first;
+ }
+
+ /**
+ * @param first the first to set
+ */
+ public void setFirst(int first) {
+ this.first = first;
+ }
+
+ /**
+ * @return the second
+ */
+ public int getSecond() {
+ return second;
+ }
+
+ /**
+ * @param second the second to set
+ */
+ public void setSecond(int second) {
+ this.second = second;
+ }
+
+ /**
+ * @return the third
+ */
+ public int getThird() {
+ return third;
+ }
+
+ /**
+ * @param third the third to set
+ */
+ public void setThird(int third) {
+ this.third = third;
+ }
+
+ /**
+ * @return total summ of the list values.
+ */
+ @Max(value=20,message="Total value should be less then 20")
+ public int getSumm(){
+ return first+second+third;
+ }
+
+ public String action() {
+ // Persist your data here
+ setActionResult("Data have been saved");
+ return null;
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+}
Property changes on:
trunk/examples/validator-demo/src/main/java/org/richfaces/example/GraphValidatorBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/examples/validator-demo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/examples/validator-demo/src/main/webapp/WEB-INF/faces-config.xml 2011-02-04
17:59:50 UTC (rev 21463)
+++ trunk/examples/validator-demo/src/main/webapp/WEB-INF/faces-config.xml 2011-02-04
18:31:43 UTC (rev 21464)
@@ -7,6 +7,11 @@
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
+ <managed-bean-name>graphValidatorBean</managed-bean-name>
+
<managed-bean-class>org.richfaces.example.GraphValidatorBean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+</managed-bean>
+<managed-bean>
<managed-bean-name>dataBean</managed-bean-name>
<managed-bean-class>org.richfaces.example.DataBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
Modified:
trunk/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java
===================================================================
---
trunk/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/iteration/ui/src/test/java/org/richfaces/component/UIDataTableTest.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -161,7 +161,7 @@
@Test
public void testCreateExtendedDataModel() {
Assert.assertFalse(table.createExtendedDataModel() instanceof Arrangeable);
- List<String> sortPriority = Arrays.asList("id2", "id0",
"id1");
+ List<Object> sortPriority = Arrays.<Object>asList("id2",
"id0", "id1");
List<UIComponent> children = table.getChildren();
ExpressionFactory expressionFactory =
facesContext.getApplication().getExpressionFactory();
ELContext elContext = facesContext.getELContext();
@@ -240,8 +240,8 @@
*/
@Test
public void testSortPriority() {
- table.setSortPriority(Collections.EMPTY_LIST);
- Assert.assertEquals(Collections.EMPTY_LIST, table.getSortPriority());
+ table.setSortPriority(Collections.emptyList());
+ Assert.assertEquals(0, table.getSortPriority().size());
}
/**
Modified:
trunk/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java
===================================================================
---
trunk/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/api/src/main/java/org/richfaces/validator/BeanValidatorService.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -21,7 +21,23 @@
*/
Collection<ValidatorDescriptor> getConstrains(FacesContext context,
ValueExpression expression,Class<?> ...groups);
-// Collection<String> validateExpression(FacesContext context,ValueExpression
expression, Object newValue,Class<?> ...groups);
+ /**
+ * <p class="changed_added_4_0">Validate expression for a new
value.</p>
+ * @param context
+ * @param expression
+ * @param newValue
+ * @param groups
+ * @return
+ */
+ Collection<String> validateExpression(FacesContext context,ValueExpression
expression, Object newValue,Class<?> ...groups);
-// Collection<String> validateObject(FacesContext context,Object object, Object
newValue,Class<?> ...groups);
+ /**
+ * <p class="changed_added_4_0">Validate entire object.</p>
+ * @param context
+ * @param object
+ * @param groups
+ * @return
+ */
+ Collection<String> validateObject(FacesContext context,Object object,
Class<?> ...groups);
+
}
Modified:
trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java
===================================================================
---
trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/api/src/main/java/org/richfaces/validator/GraphValidator.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -4,7 +4,6 @@
package org.richfaces.validator;
import java.util.Collection;
-import java.util.Set;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -19,6 +18,6 @@
public interface GraphValidator {
public Collection<String> validateGraph(FacesContext context, UIComponent
component, Object value,
- Set<String> profiles) throws ValidatorException;
+ Class<?>[] groups) throws ValidatorException;
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -30,7 +30,6 @@
import org.richfaces.javascript.ClientScriptServiceImpl;
import org.richfaces.javascript.ClientServiceConfigParser;
import org.richfaces.javascript.LibraryFunction;
-import org.richfaces.validator.BeanValidator;
import org.richfaces.validator.BeanValidatorService;
import org.richfaces.validator.BeanValidatorServiceImpl;
import org.richfaces.validator.ConverterServiceImpl;
@@ -39,8 +38,6 @@
import org.richfaces.validator.FacesValidatorService;
import org.richfaces.validator.FacesValidatorServiceImpl;
import org.richfaces.validator.InitializationException;
-import org.richfaces.validator.NullValidator;
-import org.richfaces.validator.ObjectValidator;
import org.richfaces.validator.RichFacesBeanValidatorFactory;
/**
@@ -76,23 +73,18 @@
void configureBeanValidators(ServicesFactory factory){
BeanValidatorService service ;
- ObjectValidator validator;
try {
RichFacesBeanValidatorFactory validatorFactory = new
RichFacesBeanValidatorFactory();
validatorFactory.init();
service = new BeanValidatorServiceImpl(new ValueExpressionAnalayserImpl(),
validatorFactory);
- validator = new BeanValidator(validatorFactory);
} catch (InitializationException e) {
// JSR-303 is available but not initialised.
service = new DummyBeanValidatorService();
- validator = new NullValidator();
} catch (NoClassDefFoundError e){
// JSR-303 is not avalable.
// log.warn("Validator implementations not found at classpath, default
NullValidator will be used.");
service = new DummyBeanValidatorService();
- validator = new NullValidator();
}
factory.setInstance(BeanValidatorService.class, service);
- factory.setInstance(ObjectValidator.class, validator);
}
}
Copied:
trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java
(from rev 21423,
trunk/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java)
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java
(rev 0)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/component/AbstractGraphValidator.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -0,0 +1,289 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.component;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.el.CapturingELResolver;
+import org.richfaces.el.ELContextWrapper;
+import org.richfaces.validator.FacesBeanValidator;
+import org.richfaces.validator.GraphValidator;
+import org.richfaces.validator.GraphValidatorState;
+
+/**
+ * JSF component class
+ *
+ */
+@JsfComponent(tag=(a)Tag(name="graphValidator",type=TagType.Facelets))
+public abstract class AbstractGraphValidator extends UIComponentBase {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.GraphValidator";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.GraphValidator";
+
+ /**
+ * Get object for validation
+ *
+ * @return
+ */
+ @Attribute
+ public abstract Object getValue();
+
+ /**
+ * Set object for validation
+ *
+ * @param newvalue
+ */
+ public abstract void setValue(Object newvalue);
+
+ /**
+ * Get object for validation
+ *
+ * @return
+ */
+ @Attribute
+ public abstract String getSummary();
+
+ /**
+ * Set object for validation
+ *
+ * @param newvalue
+ */
+ public abstract void setSummary(String newvalue);
+
+ /**
+ * Get set of profiles for validation
+ *
+ * @return
+ */
+ @Attribute
+ public abstract Class<?>[] getGroups();
+
+ /**
+ * Set set of profiles for validation
+ *
+ * @param newvalue
+ */
+ public abstract void setGroups(Class<?>[] newvalue);
+
+ /**
+ * Get graph validator Id.
+ *
+ * @return
+ */
+ @Attribute(defaultValue="org.richfaces.BeanValidator")
+ public abstract String getType();
+
+ /**
+ * Set graph validator Id.
+ *
+ * @param newvalue
+ */
+ public abstract void setType(String newvalue);
+
+ @Override
+ public void processDecodes(FacesContext context) {
+ GraphValidatorState validatorState = null;
+ // Detect value EL-expression.
+ ValueExpression valueExpression = getValueExpression("value");
+ if (null != valueExpression) {
+
+ Object value = getValue();
+ if (null != value && value instanceof Cloneable) {
+ try {
+ ELContext initialELContext = context.getELContext();
+
+ CapturingELResolver capturingELResolver = new
CapturingELResolver(initialELContext.getELResolver());
+ Class<?> type =
+ valueExpression.getType(new ELContextWrapper(initialELContext,
capturingELResolver));
+ if (null != type) {
+ validatorState = new GraphValidatorState();
+ Method method = getCloneMethod(value.getClass());
+ if (!Modifier.isPublic(method.getModifiers())) {
+ // Method Object#clone() is protected by default. Make it
public
+ // unless developer did it.
+ method.setAccessible(true);
+ }
+ validatorState.setCloned(method.invoke(value));
+ validatorState.setBase(capturingELResolver.getBase());
+ validatorState.setProperty(capturingELResolver.getProperty());
+ validatorState.setActive(true);
+
context.getExternalContext().getRequestMap().put(getStateId(context), validatorState);
+ }
+ } catch (NoSuchMethodException e) {
+ // do nothing, that is really not possible.
+ } catch (InvocationTargetException e) {
+ throw new FacesException(e);
+ } catch (IllegalArgumentException e) {
+ // do nothing, that is really not possible.
+ } catch (IllegalAccessException e) {
+ throw new FacesException(e);
+ }
+ }
+ }
+ super.processDecodes(context);
+ if (null != validatorState) {
+ validatorState.setActive(false);
+ }
+ }
+
+ private Method getCloneMethod(Class<?> clazz) throws NoSuchMethodException {
+ try {
+ return clazz.getDeclaredMethod("clone");
+ } catch (NoSuchMethodException e) {
+ if (null != clazz.getSuperclass()) {
+ return getCloneMethod(clazz.getSuperclass());
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ protected String getStateId(FacesContext context) {
+ String stateId = GraphValidatorState.STATE_ATTRIBUTE_PREFIX +
getClientId(context);
+ return stateId;
+ }
+
+ protected GraphValidatorState getValidatorState(FacesContext context) {
+ return (GraphValidatorState)
context.getExternalContext().getRequestMap().get(getStateId(context));
+ }
+
+ @Override
+ public void processValidators(FacesContext context) {
+ GraphValidatorState validatorState = getValidatorState(context);
+ if (null != validatorState) {
+ validatorState.setActive(true);
+ }
+ super.processValidators(context);
+ if (null != validatorState) {
+ validatorState.setActive(false);
+ validateObject(context, validatorState.getCloned());
+ context.getExternalContext().getRequestMap().remove(getStateId(context));
+ }
+ }
+
+ @Override
+ public void processUpdates(FacesContext context) {
+ super.processUpdates(context);
+ Object value = getValue();
+ validateObject(context, value);
+ }
+
+ private void validateObject(FacesContext context, Object value) {
+ if (null != value) {
+ Validator validator = context.getApplication().createValidator(getType());
+ if (validator instanceof GraphValidator) {
+ GraphValidator graphValidator = (GraphValidator) validator;
+ Collection<String> messages = graphValidator.validateGraph(context,
this, value, getGroups());
+ if (null != messages) {
+ context.renderResponse();
+ // send all validation messages.
+ String clientId = getClientId(context);
+ for (String msg : messages) {
+ // TODO - create Summary message ?
+ String summary = null != getSummary() ? getSummary() + msg :
msg;
+ context.addMessage(clientId, new
FacesMessage(FacesMessage.SEVERITY_ERROR, summary, msg));
+ }
+ }
+
+ } else {
+ throw new FacesException("Validator " +
FacesBeanValidator.BEAN_VALIDATOR_TYPE
+ + " does not implement GraphValidator");
+ }
+
+ }
+ }
+
+ @Override
+ public void encodeBegin(FacesContext context) throws IOException {
+ super.encodeBegin(context);
+ FacesBeanValidator validator = (FacesBeanValidator)
context.getApplication().createValidator(getType());
+ validator.setSummary(getSummary());
+ ValueExpression expression = getValueExpression("groups");
+ if (null != expression) {
+ validator.setGroups(expression);
+ } else {
+ validator.setGroups(getGroups());
+ }
+ setupValidators(this, validator);
+ }
+
+ @Override
+ public void encodeChildren(FacesContext context) throws IOException {
+ if (isRendered()) {
+ for (UIComponent child : getChildren()) {
+ if (child.isRendered()) {
+ child.encodeAll(context);
+ }
+ }
+ }
+ }
+
+ private void setupValidators(UIComponent component, Validator validator) {
+ Iterator<UIComponent> facetsAndChildren =
component.getFacetsAndChildren();
+ while (facetsAndChildren.hasNext()) {
+ UIComponent child = facetsAndChildren.next();
+ if (child instanceof EditableValueHolder) {
+ EditableValueHolder input = (EditableValueHolder) child;
+ setupValidator(input, validator);
+ }
+ setupValidators(child, validator);
+ }
+ }
+
+ /**
+ * @param input
+ */
+ private void setupValidator(EditableValueHolder input, Validator validator) {
+ Validator[] validators = input.getValidators();
+ for (int i = 0; i < validators.length; i++) {
+ if (validators[i].getClass().equals(validator.getClass())) {
+ return;
+ }
+ }
+ input.addValidator(validator);
+ }
+
+ @Override
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+}
Deleted:
trunk/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -1,281 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.component;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.el.ELContext;
-import javax.el.ValueExpression;
-import javax.faces.FacesException;
-import javax.faces.application.FacesMessage;
-import javax.faces.component.EditableValueHolder;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.Validator;
-
-import org.richfaces.el.CapturingELResolver;
-import org.richfaces.el.ELContextWrapper;
-import org.richfaces.validator.FacesBeanValidator;
-import org.richfaces.validator.GraphValidator;
-import org.richfaces.validator.GraphValidatorState;
-
-/**
- * JSF component class
- *
- */
-public abstract class UIGraphValidator extends UIComponentBase {
-
- public static final String COMPONENT_TYPE =
"org.richfaces.GraphValidator";
-
- public static final String COMPONENT_FAMILY =
"org.richfaces.GraphValidator";
-
- /**
- * Get object for validation
- *
- * @return
- */
- public abstract Object getValue();
-
- /**
- * Set object for validation
- *
- * @param newvalue
- */
- public abstract void setValue(Object newvalue);
-
- /**
- * Get object for validation
- *
- * @return
- */
- public abstract String getSummary();
-
- /**
- * Set object for validation
- *
- * @param newvalue
- */
- public abstract void setSummary(String newvalue);
-
- /**
- * Get set of profiles for validation
- *
- * @return
- */
- public abstract Set<String> getProfiles();
-
- /**
- * Set set of profiles for validation
- *
- * @param newvalue
- */
- public abstract void setProfiles(Object newvalue);
-
- /**
- * Get graph validator Id.
- *
- * @return
- */
- public abstract String getType();
-
- /**
- * Set graph validator Id.
- *
- * @param newvalue
- */
- public abstract void setType(String newvalue);
-
- @Override
- public void processDecodes(FacesContext context) {
- GraphValidatorState validatorState = null;
- // Detect value EL-expression.
- ValueExpression valueExpression = getValueExpression("value");
- if (null != valueExpression) {
-
- Object value = getValue();
- if (null != value && value instanceof Cloneable) {
- try {
- ELContext initialELContext = context.getELContext();
-
- CapturingELResolver capturingELResolver = new
CapturingELResolver(initialELContext.getELResolver());
- Class<?> type =
- valueExpression.getType(new ELContextWrapper(initialELContext,
capturingELResolver));
- if (null != type) {
- validatorState = new GraphValidatorState();
- Method method = getCloneMethod(value.getClass());
- if (!Modifier.isPublic(method.getModifiers())) {
- // Method Object#clone() is protected by default. Make it
public
- // unless developer did it.
- method.setAccessible(true);
- }
- validatorState.setCloned(method.invoke(value));
- validatorState.setBase(capturingELResolver.getBase());
- validatorState.setProperty(capturingELResolver.getProperty());
- validatorState.setActive(true);
-
context.getExternalContext().getRequestMap().put(getStateId(context), validatorState);
- }
- } catch (NoSuchMethodException e) {
- // do nothing, that is really not possible.
- } catch (InvocationTargetException e) {
- throw new FacesException(e);
- } catch (IllegalArgumentException e) {
- // do nothing, that is really not possible.
- } catch (IllegalAccessException e) {
- throw new FacesException(e);
- }
- }
- }
- super.processDecodes(context);
- if (null != validatorState) {
- validatorState.setActive(false);
- }
- }
-
- private Method getCloneMethod(Class<?> clazz) throws NoSuchMethodException {
- try {
- return clazz.getDeclaredMethod("clone");
- } catch (NoSuchMethodException e) {
- if (null != clazz.getSuperclass()) {
- return getCloneMethod(clazz.getSuperclass());
- } else {
- throw e;
- }
- }
- }
-
- protected String getStateId(FacesContext context) {
- String stateId = GraphValidatorState.STATE_ATTRIBUTE_PREFIX +
getClientId(context);
- return stateId;
- }
-
- protected GraphValidatorState getValidatorState(FacesContext context) {
- return (GraphValidatorState)
context.getExternalContext().getRequestMap().get(getStateId(context));
- }
-
- @Override
- public void processValidators(FacesContext context) {
- GraphValidatorState validatorState = getValidatorState(context);
- if (null != validatorState) {
- validatorState.setActive(true);
- }
- super.processValidators(context);
- if (null != validatorState) {
- validatorState.setActive(false);
- validateObject(context, validatorState.getCloned());
- context.getExternalContext().getRequestMap().remove(getStateId(context));
- }
- }
-
- @Override
- public void processUpdates(FacesContext context) {
- super.processUpdates(context);
- Object value = getValue();
- validateObject(context, value);
- }
-
- private void validateObject(FacesContext context, Object value) {
- if (null != value) {
- Validator validator = context.getApplication().createValidator(getType());
- if (validator instanceof GraphValidator) {
- GraphValidator graphValidator = (GraphValidator) validator;
- Collection<String> messages = graphValidator.validateGraph(context,
this, value, getProfiles());
- if (null != messages) {
- context.renderResponse();
- // send all validation messages.
- String clientId = getClientId(context);
- for (String msg : messages) {
- // TODO - create Summary message ?
- String summary = null != getSummary() ? getSummary() + msg :
msg;
- context.addMessage(clientId, new
FacesMessage(FacesMessage.SEVERITY_ERROR, summary, msg));
- }
- }
-
- } else {
- throw new FacesException("Validator " +
FacesBeanValidator.BEAN_VALIDATOR_TYPE
- + " does not implement GraphValidator");
- }
-
- }
- }
-
- @Override
- public void encodeBegin(FacesContext context) throws IOException {
- super.encodeBegin(context);
- FacesBeanValidator validator = (FacesBeanValidator)
context.getApplication().createValidator(getType());
- validator.setSummary(getSummary());
- ValueExpression expression = getValueExpression("profiles");
- if (null != expression) {
- validator.setProfiles(expression);
- } else {
- validator.setProfiles(getProfiles());
- }
- setupValidators(this, validator);
- }
-
- @Override
- public void encodeChildren(FacesContext context) throws IOException {
- if (isRendered()) {
- for (UIComponent child : getChildren()) {
- if (child.isRendered()) {
- child.encodeAll(context);
- }
- }
- }
- }
-
- private void setupValidators(UIComponent component, Validator validator) {
- Iterator<UIComponent> facetsAndChildren =
component.getFacetsAndChildren();
- while (facetsAndChildren.hasNext()) {
- UIComponent child = facetsAndChildren.next();
- if (child instanceof EditableValueHolder) {
- EditableValueHolder input = (EditableValueHolder) child;
- setupValidator(input, validator);
- }
- setupValidators(child, validator);
- }
- }
-
- /**
- * @param input
- */
- private void setupValidator(EditableValueHolder input, Validator validator) {
- Validator[] validators = input.getValidators();
- for (int i = 0; i < validators.length; i++) {
- if (validators[i] instanceof FacesBeanValidator) {
- return;
- }
- }
- input.addValidator(validator);
- }
-
- @Override
- public boolean getRendersChildren() {
- return true;
- }
-
-}
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 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -59,6 +59,7 @@
import org.richfaces.renderkit.html.FormClientValidatorRenderer;
import org.richfaces.validator.BeanValidatorService;
import org.richfaces.validator.ConverterDescriptor;
+import org.richfaces.validator.FacesBeanValidator;
import org.richfaces.validator.FacesConverterService;
import org.richfaces.validator.FacesValidatorService;
import org.richfaces.validator.ValidatorDescriptor;
@@ -279,7 +280,7 @@
FacesValidatorService facesValidatorService =
ServiceTracker.getService(facesContext,
FacesValidatorService.class);
for (Validator validator : facesValidators) {
- if (validator instanceof BeanValidator) {
+ if (validator instanceof BeanValidator || validator instanceof
FacesBeanValidator) {
ValueExpression valueExpression =
component.getValueExpression(VALUE);
if (null != valueExpression) {
BeanValidatorService beanValidatorService =
ServiceTracker.getService(facesContext,
Deleted: trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidator.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidator.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidator.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -1,112 +0,0 @@
-/**
- *
- */
-package org.richfaces.validator;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Set;
-
-import javax.faces.FacesException;
-import javax.faces.context.FacesContext;
-import javax.validation.ConstraintViolation;
-import javax.validation.Validator;
-import javax.validation.groups.Default;
-
-/**
- * @author asmirnov
- *
- */
-public class BeanValidator extends ObjectValidator {
-
- private static final Class<?>[] DEFAULT_PROFILE = new Class[] {Default.class};
- private final BeanValidatorFactory validatorFactory;
-
-
- public BeanValidator(BeanValidatorFactory validatorFactory) {
- this.validatorFactory = validatorFactory;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.validator.ObjectValidator#validate(java.lang.Object,
java.lang.String, java.lang.Object,
- * java.util.Locale)
- */
- @Override
- protected Collection<String> validate(FacesContext facesContext, Object base,
String property, Object value,
- Set<String> profiles) {
- @SuppressWarnings("rawtypes")
- Class beanType = base.getClass();
- @SuppressWarnings("unchecked")
- Set<ConstraintViolation<Object>> constrains =
- getValidator(facesContext).validateValue(beanType, property, value,
getGroups(profiles));
- return extractMessages(constrains);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.validator.ObjectValidator#validateGraph(javax.faces.context
.FacesContext, java.lang.Object,
- * java.util.Set)
- */
- @Override
- public Collection<String> validateGraph(FacesContext context, Object value,
Set<String> profiles) {
- Class<?>[] groups = getGroups(profiles);
- Set<ConstraintViolation<Object>> violations =
getValidator(context).validate(value, groups);
- Collection<String> messages = extractMessages(violations);
- if (null != parent) {
- Collection<String> parentMessages = parent.validateGraph(context,
value, profiles);
- if (null != messages) {
- if (null != parentMessages) {
- messages.addAll(parentMessages);
- }
- } else {
- messages = parentMessages;
- }
- }
- return messages;
- }
-
- private Class<?>[] getGroups(Set<String> profiles) {
- Class<?>[] groups = null;
- if (null != profiles) {
- groups = new Class<?>[profiles.size()];
- int i = 0;
- for (String group : profiles) {
- try {
- groups[i] = Class.forName(group, false,
Thread.currentThread().getContextClassLoader());
- } catch (ClassNotFoundException e) {
- try {
- groups[i] = Class.forName(group);
- } catch (ClassNotFoundException e1) {
- throw new FacesException("Bean validation group not found
" + group, e1);
- }
- }
- i++;
- }
-
- } else {
- groups = DEFAULT_PROFILE;
- }
- return groups;
- }
-
- private Collection<String>
extractMessages(Set<ConstraintViolation<Object>> violations) {
- Collection<String> messages = null;
- if (null != violations && violations.size() > 0) {
- messages = new ArrayList<String>(violations.size());
- for (ConstraintViolation<? extends Object> constraintViolation :
violations) {
- messages.add(constraintViolation.getMessage());
- }
-
- }
- return messages;
- }
-
- protected Validator getValidator(FacesContext facesContext) {
- Validator beanValidator = validatorFactory.getValidator(facesContext);
- return beanValidator;
- }
-
-}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/BeanValidatorServiceImpl.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -3,23 +3,34 @@
*/
package org.richfaces.validator;
+import java.beans.FeatureDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.EmptyStackException;
import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import java.util.Stack;
+import javax.el.ELContext;
import javax.el.ELException;
+import javax.el.ELResolver;
import javax.el.ValueExpression;
+import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
+import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.metadata.ElementDescriptor.ConstraintFinder;
import javax.validation.metadata.PropertyDescriptor;
+import org.richfaces.el.ELContextWrapper;
import org.richfaces.el.ValueDescriptor;
import org.richfaces.el.ValueExpressionAnalayser;
@@ -32,6 +43,9 @@
public class BeanValidatorServiceImpl implements BeanValidatorService {
private static final Collection<String> HIDDEN_PARAMS =
ImmutableSet.of("message","payload","groups");
+ private static final String FACES_CONTEXT_IS_NULL = "Faces context is
null";
+ private static final String INPUT_PARAMETERS_IS_NOT_CORRECT = "Input parameters
is not correct.";
+ private static final Class<?>[] DEFAULT_GROUP={};
private final ValueExpressionAnalayser analayser;
private final BeanValidatorFactory validatorFactory;
@@ -130,4 +144,321 @@
}
return annotationClass;
}
+
+ public Collection<String> validateExpression(FacesContext context,
ValueExpression expression, Object newValue,
+ Class<?>... groups) {
+ if (null == context) {
+ throw new FacesException(INPUT_PARAMETERS_IS_NOT_CORRECT);
+ }
+ Collection<String> validationMessages = Collections.emptySet();
+ if (null != expression) {
+ ELContext elContext = context.getELContext();
+ ValidationResolver validationResolver =
+ createValidationResolver(context, elContext.getELResolver(), groups);
+ ELContextWrapper wrappedElContext = new ELContextWrapper(elContext,
validationResolver);
+ try {
+ expression.setValue(wrappedElContext, newValue);
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+ if (!validationResolver.isValid()) {
+ validationMessages = validationResolver.getValidationMessages();
+ }
+ }
+ return validationMessages;
+ }
+
+
+ protected ValidationResolver createValidationResolver(FacesContext context,
ELResolver parent, Class<?>[] groups) {
+ return new ValidationResolver(parent, context, groups);
+ }
+
+ /**
+ * @author asmirnov
+ *
+ */
+ protected static class BasePropertyPair {
+ private final Object base;
+ private final Object property;
+
+ /**
+ * @param base
+ * @param property
+ */
+ public BasePropertyPair(Object base, Object property) {
+ this.base = base;
+ this.property = property;
+ }
+
+ /**
+ * @return the base
+ */
+ public Object getBase() {
+ return base;
+ }
+
+ /**
+ * @return the property
+ */
+ public Object getProperty() {
+ return property;
+ }
+
+ }
+
+ /**
+ * Class for identify validator instance by locale
+ *
+ * @author amarkhel
+ *
+ */
+ protected static class ValidatorKey {
+ private final Class<? extends Object> validatableClass;
+ private final Locale locale;
+
+ /**
+ * Constructor for ValidatorKey object
+ *
+ * @param validatableClass
+ * - class to validate
+ * @param locale
+ * - User locale to determine Resource bundle, used during validation
process
+ */
+ public ValidatorKey(Class<? extends Object> validatableClass, Locale
locale) {
+ this.validatableClass = validatableClass;
+ this.locale = locale;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((this.locale == null) ? 0 :
this.locale.hashCode());
+ result = prime * result + ((this.validatableClass == null) ? 0 :
this.validatableClass.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ValidatorKey other = (ValidatorKey) obj;
+ if (this.locale == null) {
+ if (other.locale != null) {
+ return false;
+ }
+ } else if (!this.locale.equals(other.locale)) {
+ return false;
+ }
+ if (this.validatableClass == null) {
+ if (other.validatableClass != null) {
+ return false;
+ }
+ } else if (!this.validatableClass.equals(other.validatableClass)) {
+ return false;
+ }
+ return true;
+ }
+
+
+
+ }
+
+ /**
+ * Wrapper class for a {@link ELResolver}. For a setValue method, perform validation
instead of real assignment.
+ *
+ * @author asmirnov
+ *
+ */
+ final class ValidationResolver extends ELResolver {
+
+ /**
+ * Original resolver.
+ */
+ private final ELResolver parent;
+
+ private boolean valid = true;
+
+ private Collection<String> validationMessages = null;
+
+ private Stack<BasePropertyPair> valuesStack;
+
+ private Class<?>[] groups;
+
+ private FacesContext facesContext;
+
+ private boolean clonedObject = false;
+
+ /**
+ * @param parent
+ * @param context
+ */
+ public ValidationResolver(ELResolver parent, FacesContext context,
Class<?>[] groups) {
+ this.parent = parent;
+ this.valuesStack = new Stack<BasePropertyPair>();
+ this.groups = groups;
+ this.facesContext = context;
+ }
+
+ public boolean isValid() {
+ return valid;
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @return
+ * @see javax.el.ELResolver#getCommonPropertyType(javax.el.ELContext,
java.lang.Object)
+ */
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ return parent.getCommonPropertyType(context, base);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @return
+ * @see javax.el.ELResolver#getFeatureDescriptors(javax.el.ELContext,
java.lang.Object)
+ */
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
Object base) {
+ return parent.getFeatureDescriptors(context, base);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @return
+ * @see javax.el.ELResolver#getType(javax.el.ELContext, java.lang.Object,
java.lang.Object)
+ */
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ return parent.getType(context, base, property);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @return
+ * @see javax.el.ELResolver#getValue(javax.el.ELContext, java.lang.Object,
java.lang.Object)
+ */
+ public Object getValue(ELContext context, Object base, Object property) {
+ Object value = ClonedObjectResolver.resolveCloned(context, base, property);
+ if (null != value) {
+ this.clonedObject = true;
+ context.setPropertyResolved(true);
+ } else {
+ value = parent.getValue(context, base, property);
+ }
+ valuesStack.push(new BasePropertyPair(base, property));
+ return value;
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @return
+ * @see javax.el.ELResolver#isReadOnly(javax.el.ELContext, java.lang.Object,
java.lang.Object)
+ */
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ return parent.isReadOnly(context, base, property);
+ }
+
+ /**
+ * @param context
+ * @param base
+ * @param property
+ * @param value
+ * @see javax.el.ELResolver#setValue(javax.el.ELContext, java.lang.Object,
java.lang.Object, java.lang.Object)
+ */
+ public void setValue(ELContext context, Object base, Object property, Object
value) {
+ if (null != base && null != property) {
+ // TODO - detect value object from inderect references ( e.g. data table
variables ).
+ if (this.clonedObject) {
+ parent.setValue(context, base, property, value);
+ }
+ context.setPropertyResolved(true);
+ // For Arrays, Collection or Map use parent base and property.
+ BasePropertyPair basePropertyPair = lookupBeanProperty(new
BasePropertyPair(base, property));
+ base = basePropertyPair.getBase();
+ property = basePropertyPair.getProperty();
+ if (null != base && null != property) {
+ //
https://jira.jboss.org/jira/browse/RF-4034
+ // apache el looses locale information during value
+ // resolution,
+ // so we use our own
+ validationMessages = validate(facesContext, base,
property.toString(), value, groups);
+ valid = null == validationMessages || 0 ==
validationMessages.size();
+
+ }
+ }
+ }
+
+ private BasePropertyPair lookupBeanProperty(BasePropertyPair pair) {
+ Object base = pair.getBase();
+ if (null != base && (base instanceof Collection || base instanceof
Map || base.getClass().isArray())) {
+ try {
+ pair = lookupBeanProperty(valuesStack.pop());
+ } catch (EmptyStackException e) {
+ // Do nothing, this is a first item.
+ }
+ }
+ return pair;
+ }
+
+ /**
+ * @return the validationMessages
+ */
+ public Collection<String> getValidationMessages() {
+ return validationMessages;
+ }
+
+ }
+
+ protected Collection<String> validate(FacesContext facesContext, Object base,
String property, Object value,
+ Class<?>[] groups) {
+ @SuppressWarnings("rawtypes")
+ Class beanType = base.getClass();
+ @SuppressWarnings("unchecked")
+ Set<ConstraintViolation<Object>> constrains =
+ getValidator(facesContext).validateValue(beanType, property, value,
getGroups(groups));
+ return extractMessages(constrains);
+ }
+
+ private Class<?>[] getGroups(Class<?>[] groups) {
+ return null==groups?DEFAULT_GROUP:groups;
+ }
+
+ public Collection<String> validateObject(FacesContext context, Object value,
Class<?>... groups) {
+ Set<ConstraintViolation<Object>> violations =
getValidator(context).validate(value, getGroups(groups));
+ Collection<String> messages = extractMessages(violations);
+ return messages;
+ }
+
+ private Collection<String>
extractMessages(Set<ConstraintViolation<Object>> violations) {
+ Collection<String> messages = null;
+ if (null != violations && violations.size() > 0) {
+ messages = new ArrayList<String>(violations.size());
+ for (ConstraintViolation<? extends Object> constraintViolation :
violations) {
+ messages.add(constraintViolation.getMessage());
+ }
+
+ }
+ return messages;
+ }
+
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/DummyBeanValidatorService.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -23,4 +23,13 @@
return Collections.emptySet();
}
+ public Collection<String> validateExpression(FacesContext context,
ValueExpression expression, Object newValue,
+ Class<?>... groups) {
+ return Collections.emptySet();
+ }
+
+ public Collection<String> validateObject(FacesContext context, Object object,
Class<?>... groups) {
+ return Collections.emptySet();
+ }
+
}
Modified:
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -24,7 +24,6 @@
import java.text.MessageFormat;
import java.util.Collection;
import java.util.Locale;
-import java.util.Set;
import javax.el.ELException;
import javax.el.ValueExpression;
@@ -36,12 +35,20 @@
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.cdk.annotations.JsfValidator;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+
+import com.google.common.base.Strings;
+
/**
* Implementation of the JSF validator to use with Bean Validation / Hibernate validator
*
* @author asmirnov
*
*/
+@JsfValidator(id=FacesBeanValidator.BEAN_VALIDATOR_TYPE,tag=(a)Tag(name="beanValidator",type=TagType.Facelets))
public class FacesBeanValidator implements Serializable, Validator, GraphValidator {
public static final String BEAN_VALIDATOR_TYPE =
"org.richfaces.BeanValidator";
@@ -53,10 +60,14 @@
private String summary = null;
- private ValueExpression profilesExpression = null;
+ private ValueExpression groupsExpression = null;
- private Set<String> profiles = null;
+ private Class<?>[] groups = null;
+ private BeanValidatorService validatorService;
+ public FacesBeanValidator() {
+ this.validatorService = ServiceTracker.getService(BeanValidatorService.class);
+ }
/**
* @return the summary
*/
@@ -100,9 +111,9 @@
ValueExpression valueExpression =
component.getValueExpression("value");
if (null != valueExpression) {
Collection<String> messages =
- ObjectValidator.getInstance(context).validate(context,
valueExpression, convertedValue,
- getProfiles());
- if (null != messages) {
+ validatorService.validateExpression(context, valueExpression,
convertedValue,
+ getGroups());
+ if (!messages.isEmpty()) {
input.setValid(false);
Object label = getLabel(context, component);
Locale locale = context.getViewRoot().getLocale();
@@ -111,10 +122,10 @@
//
https://jira.jboss.org/jira/browse/RF-7636 -
// format values.
String formattedMessage = formatMessage(msg, locale, label,
convertedValue); // create Summary message ?
- String summaryString = getSummary() != null ? getSummary() :
formattedMessage;
- summaryString = formatMessage(summaryString, locale, label,
convertedValue);
+ String summary = getSummary();
+ String formattedSummary = Strings.isNullOrEmpty(summary) ?
formattedMessage:formatMessage(summary, locale, label, convertedValue);
context.addMessage(component.getClientId(context), new
FacesMessage(
- FacesMessage.SEVERITY_ERROR, summaryString,
formattedMessage));
+ FacesMessage.SEVERITY_ERROR, formattedSummary,
formattedMessage));
}
}
}
@@ -145,21 +156,20 @@
}
public Collection<String> validateGraph(FacesContext context, UIComponent
component, Object value,
- Set<String> profiles) throws ValidatorException {
- ObjectValidator beanValidator = ObjectValidator.getInstance(context);
- Collection<String> messages = beanValidator.validateGraph(context, value,
profiles);
+ Class<?>[] groups) throws ValidatorException {
+ Collection<String> messages = validatorService.validateObject(context,
value, groups);
return messages;
}
/**
* @return the profiles
*/
- public Set<String> getProfiles() {
- Set<String> profiles;
- if (null != profilesExpression) {
- profiles = (Set<String>)
profilesExpression.getValue(FacesContext.getCurrentInstance().getELContext());
+ public Class<?>[] getGroups() {
+ Class<?>[] profiles;
+ if (null != groupsExpression) {
+ profiles = (Class<?>[])
groupsExpression.getValue(FacesContext.getCurrentInstance().getELContext());
} else {
- profiles = this.profiles;
+ profiles = this.groups;
}
return profiles;
}
@@ -168,11 +178,11 @@
* @param profiles
* the profiles to set
*/
- public void setProfiles(Set<String> profiles) {
- this.profiles = profiles;
+ public void setGroups(Class<?>... profiles) {
+ this.groups = profiles;
}
- public void setProfiles(ValueExpression profilesExpression) {
- this.profilesExpression = profilesExpression;
+ public void setGroups(ValueExpression profilesExpression) {
+ this.groupsExpression = profilesExpression;
}
}
\ No newline at end of file
Deleted: trunk/ui/validator/ui/src/main/java/org/richfaces/validator/NullValidator.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/NullValidator.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/NullValidator.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -1,42 +0,0 @@
-/**
- *
- */
-package org.richfaces.validator;
-
-import java.util.Collection;
-import java.util.Set;
-
-import javax.faces.context.FacesContext;
-
-/**
- * @author asmirnov
- *
- */
-public class NullValidator extends ObjectValidator {
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.validator.ObjectValidator#validate(java.lang.Object,
java.lang.String, java.lang.Object,
- * java.util.Locale)
- */
- @Override
- protected Collection<String> validate(FacesContext facesContext, Object base,
String property, Object value,
- Set<String> profiles) {
- // do nothing.
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.richfaces.validator.ObjectValidator#validateGraph(javax.faces.context.FacesContext,
java.lang.Object,
- * java.util.Set)
- */
- @Override
- public Collection<String> validateGraph(FacesContext context, Object value,
Set<String> profiles) {
- // do nothing
- return null;
- }
-
-}
Deleted: trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ObjectValidator.java
===================================================================
---
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ObjectValidator.java 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/ui/src/main/java/org/richfaces/validator/ObjectValidator.java 2011-02-04
18:31:43 UTC (rev 21464)
@@ -1,420 +0,0 @@
-package org.richfaces.validator;
-
-import java.beans.FeatureDescriptor;
-import java.util.Collection;
-import java.util.EmptyStackException;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.Stack;
-
-import javax.el.ELContext;
-import javax.el.ELException;
-import javax.el.ELResolver;
-import javax.el.ValueExpression;
-import javax.faces.FacesException;
-import javax.faces.application.Application;
-import javax.faces.context.FacesContext;
-
-import org.richfaces.application.ServiceTracker;
-import org.richfaces.el.ELContextWrapper;
-
-public abstract class ObjectValidator {
-
- private static final String RESOURCE_BUNDLE_IS_NOT_REGISTERED_FOR_CURRENT_LOCALE =
- "Resource bundle is not registered for current locale";
-
- private static final String FACES_CONTEXT_IS_NULL = "Faces context is
null";
- private static final String INPUT_PARAMETERS_IS_NOT_CORRECT = "Input parameters
is not correct.";
- private static final String LOCALE_IS_NOT_SET = "Locale is not set";
- private static final String VIEW_ROOT_IS_NOT_INITIALIZED = "ViewRoot is not
initialized";
-
- protected final ObjectValidator parent;
-
- ObjectValidator() {
- this.parent = null;
- }
-
- ObjectValidator(ObjectValidator parent) {
- this.parent = parent;
- }
-
- /**
- * Return BeanValidator object from a ServletContext attribute. Create new instance
if none is defined.
- *
- * @param context
- * @return
- */
- public static ObjectValidator getInstance(FacesContext context) {
- return ServiceTracker.getService(context, ObjectValidator.class);
- }
-
- public abstract Collection<String> validateGraph(FacesContext context, Object
value, Set<String> profiles);
-
- /**
- * Perform Validation for a new value.
- *
- * @param context
- * current faces context.
- * @param target
- * {@link ValueExpression} for a value assignment.
- * @param value
- * new value for validation
- * @param profiles
- * TODO
- * @return null if no validation errors. Array of the validation messages otherwise.
- * @throws FacesException
- * if locale or context not properly initialized
- */
- public Collection<String> validate(FacesContext context, ValueExpression
target, Object value, Set<String> profiles) {
- if (null == context) {
- throw new FacesException(INPUT_PARAMETERS_IS_NOT_CORRECT);
- }
- Collection<String> validationMessages = null;
- if (null != target) {
- ELContext elContext = context.getELContext();
- ValidationResolver validationResolver =
- createValidationResolver(context, elContext.getELResolver(), profiles);
- ELContextWrapper wrappedElContext = new ELContextWrapper(elContext,
validationResolver);
- try {
- target.setValue(wrappedElContext, value);
- } catch (ELException e) {
- throw new FacesException(e);
- }
- if (!validationResolver.isValid()) {
- validationMessages = validationResolver.getValidationMessages();
- }
- if (null != parent) {
- Collection<String> parentMessages = parent.validate(context,
target, value, profiles);
- if (null != validationMessages) {
- if (null != parentMessages) {
- validationMessages.addAll(parentMessages);
- }
- } else {
- validationMessages = parentMessages;
- }
- }
-
- }
- return validationMessages;
- }
-
- /**
- * Validate bean property for a new value.
- *
- * @param facesContext
- * TODO
- * @param base
- * - bean
- * @param property
- * - bean property name.
- * @param value
- * new value.
- * @param profiles
- * TODO
- *
- * @return null for a valid value, array of the validation messages othervise.
- */
- protected abstract Collection<String> validate(FacesContext facesContext,
Object base, String property,
- Object value, Set<String> profiles);
-
- static Locale calculateLocale(FacesContext context) {
- if (null == context.getViewRoot()) {
- throw new FacesException(VIEW_ROOT_IS_NOT_INITIALIZED);
- } else if (null == context.getViewRoot().getLocale()) {
- throw new FacesException(LOCALE_IS_NOT_SET);
- }
- Locale locale = context.getViewRoot().getLocale();
- return locale;
- }
-
- static ResourceBundle getResourceBundle(FacesContext facesContext, String name) {
- ResourceBundle bundle = null;
- if (null != facesContext) {
- Application application = facesContext.getApplication();
- try {
- bundle = application.getResourceBundle(facesContext, name);
-
- } catch (Exception e) {
- // Let one more attempt to load resource
- }
- }
- if (null == bundle) {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- if (null == classLoader) {
- classLoader = ObjectValidator.class.getClassLoader();
- }
- try {
- bundle = ResourceBundle.getBundle(name, calculateLocale(facesContext),
classLoader);
-
- } catch (MissingResourceException e) {
- // Do nothing, use default bundle.
- }
- }
- return bundle;
- }
-
- protected ValidationResolver createValidationResolver(FacesContext context,
ELResolver parent, Set<String> profiles) {
- return new ValidationResolver(parent, context, profiles);
- }
-
- /**
- * @author asmirnov
- *
- */
- protected static class BasePropertyPair {
- private final Object base;
- private final Object property;
-
- /**
- * @param base
- * @param property
- */
- public BasePropertyPair(Object base, Object property) {
- this.base = base;
- this.property = property;
- }
-
- /**
- * @return the base
- */
- public Object getBase() {
- return base;
- }
-
- /**
- * @return the property
- */
- public Object getProperty() {
- return property;
- }
-
- }
-
- /**
- * Class for identify validator instance by locale
- *
- * @author amarkhel
- *
- */
- protected static class ValidatorKey {
- private final Class<? extends Object> validatableClass;
- private final Locale locale;
-
- /**
- * Constructor for ValidatorKey object
- *
- * @param validatableClass
- * - class to validate
- * @param locale
- * - User locale to determine Resource bundle, used during validation
process
- */
- public ValidatorKey(Class<? extends Object> validatableClass, Locale
locale) {
- this.validatableClass = validatableClass;
- this.locale = locale;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((this.locale == null) ? 0 :
this.locale.hashCode());
- result = prime * result + ((this.validatableClass == null) ? 0 :
this.validatableClass.hashCode());
- return result;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- ValidatorKey other = (ValidatorKey) obj;
- if (this.locale == null) {
- if (other.locale != null) {
- return false;
- }
- } else if (!this.locale.equals(other.locale)) {
- return false;
- }
- if (this.validatableClass == null) {
- if (other.validatableClass != null) {
- return false;
- }
- } else if (!this.validatableClass.equals(other.validatableClass)) {
- return false;
- }
- return true;
- }
-
-
-
- }
-
- /**
- * Wrapper class for a {@link ELResolver}. For a setValue method, perform validation
instead of real assignment.
- *
- * @author asmirnov
- *
- */
- final class ValidationResolver extends ELResolver {
-
- /**
- * Original resolver.
- */
- private final ELResolver parent;
-
- private boolean valid = true;
-
- private Collection<String> validationMessages = null;
-
- private Stack<BasePropertyPair> valuesStack;
-
- private Set<String> profiles;
-
- private FacesContext facesContext;
-
- private boolean clonedObject = false;
-
- /**
- * @param parent
- * @param context
- */
- public ValidationResolver(ELResolver parent, FacesContext context,
Set<String> profiles) {
- this.parent = parent;
- this.valuesStack = new Stack<BasePropertyPair>();
- this.profiles = profiles;
- this.facesContext = context;
- }
-
- public boolean isValid() {
- return valid;
- }
-
- /**
- * @param context
- * @param base
- * @return
- * @see javax.el.ELResolver#getCommonPropertyType(javax.el.ELContext,
java.lang.Object)
- */
- public Class<?> getCommonPropertyType(ELContext context, Object base) {
- return parent.getCommonPropertyType(context, base);
- }
-
- /**
- * @param context
- * @param base
- * @return
- * @see javax.el.ELResolver#getFeatureDescriptors(javax.el.ELContext,
java.lang.Object)
- */
- public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
Object base) {
- return parent.getFeatureDescriptors(context, base);
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @return
- * @see javax.el.ELResolver#getType(javax.el.ELContext, java.lang.Object,
java.lang.Object)
- */
- public Class<?> getType(ELContext context, Object base, Object property) {
- return parent.getType(context, base, property);
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @return
- * @see javax.el.ELResolver#getValue(javax.el.ELContext, java.lang.Object,
java.lang.Object)
- */
- public Object getValue(ELContext context, Object base, Object property) {
- Object value = ClonedObjectResolver.resolveCloned(context, base, property);
- if (null != value) {
- this.clonedObject = true;
- context.setPropertyResolved(true);
- } else {
- value = parent.getValue(context, base, property);
- }
- valuesStack.push(new BasePropertyPair(base, property));
- return value;
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @return
- * @see javax.el.ELResolver#isReadOnly(javax.el.ELContext, java.lang.Object,
java.lang.Object)
- */
- public boolean isReadOnly(ELContext context, Object base, Object property) {
- return parent.isReadOnly(context, base, property);
- }
-
- /**
- * @param context
- * @param base
- * @param property
- * @param value
- * @see javax.el.ELResolver#setValue(javax.el.ELContext, java.lang.Object,
java.lang.Object, java.lang.Object)
- */
- public void setValue(ELContext context, Object base, Object property, Object
value) {
- if (null != base && null != property) {
- // TODO - detect value object from inderect references ( e.g. data table
variables ).
- if (this.clonedObject) {
- parent.setValue(context, base, property, value);
- }
- context.setPropertyResolved(true);
- // For Arrays, Collection or Map use parent base and property.
- BasePropertyPair basePropertyPair = lookupBeanProperty(new
BasePropertyPair(base, property));
- base = basePropertyPair.getBase();
- property = basePropertyPair.getProperty();
- if (null != base && null != property) {
- //
https://jira.jboss.org/jira/browse/RF-4034
- // apache el looses locale information during value
- // resolution,
- // so we use our own
- validationMessages = validate(facesContext, base,
property.toString(), value, profiles);
- valid = null == validationMessages || 0 ==
validationMessages.size();
-
- }
- }
- }
-
- private BasePropertyPair lookupBeanProperty(BasePropertyPair pair) {
- Object base = pair.getBase();
- if (null != base && (base instanceof Collection || base instanceof
Map || base.getClass().isArray())) {
- try {
- pair = lookupBeanProperty(valuesStack.pop());
- } catch (EmptyStackException e) {
- // Do nothing, this is a first item.
- }
- }
- return pair;
- }
-
- /**
- * @return the validationMessages
- */
- public Collection<String> getValidationMessages() {
- return validationMessages;
- }
-
- }
-
-}
\ No newline at end of file
Modified:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss 2011-02-04
17:59:50 UTC (rev 21463)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/msg.ecss 2011-02-04
18:31:43 UTC (rev 21464)
@@ -5,7 +5,7 @@
height:18ex;
}
/* all messages */
-.rf-msg-err, rf-msg-ftl, rf-msg-inf, rf-msg-wrn {
+.rf-msg-err, .rf-msg-ftl, .rf-msg-inf, .rf-msg-wrn {
display:inline-block;
padding-right:2px;
padding-left:20px;