Author: alexsmirnov
Date: 2010-09-14 18:30:39 -0400 (Tue, 14 Sep 2010)
New Revision: 19206
Added:
branches/RF-8742/ui/validator/api/src/main/java/org/
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorEvent.java
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorListener.java
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java
branches/RF-8742/ui/validator/impl/src/main/java/org/
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/NullValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClonedObjectResolver.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIBeanValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorHandler.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorTag.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/GraphValidatorHandler.java
Modified:
branches/RF-8742/ui/validator/api/pom.xml
branches/RF-8742/ui/validator/api/src/main/java/META-INF/MANIFEST.MF
branches/RF-8742/ui/validator/impl/pom.xml
branches/RF-8742/ui/validator/pom.xml
branches/RF-8742/ui/validator/ui/pom.xml
Log:
RESOLVED - issue RF-9214: CSV: create project in sandbox
https://jira.jboss.org/browse/RF-9214
Modified: branches/RF-8742/ui/validator/api/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/api/pom.xml 2010-09-14 18:41:14 UTC (rev 19205)
+++ branches/RF-8742/ui/validator/api/pom.xml 2010-09-14 22:30:39 UTC (rev 19206)
@@ -52,6 +52,12 @@
<groupId>org.richfaces.ui.common</groupId>
<artifactId>richfaces-ui-common-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<scm>
Property changes on: branches/RF-8742/ui/validator/api/pom.xml
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Property changes on: branches/RF-8742/ui/validator/api/src/main/java/META-INF/MANIFEST.MF
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Added:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorEvent.java
===================================================================
---
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorEvent.java
(rev 0)
+++
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorEvent.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,68 @@
+/**
+ * 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.event;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ValidatorEvent extends FacesEvent {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5593837134704144777L;
+
+ public ValidatorEvent(UIComponent component) {
+ super(component);
+ // TODO Auto-generated constructor stub
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.event.FacesEvent#isAppropriateListener(javax.faces.event.FacesListener)
+ */
+ @Override
+ public boolean isAppropriateListener(FacesListener listener) {
+ // TODO Auto-generated method stub
+ return listener instanceof ValidatorListener;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.event.FacesEvent#processListener(javax.faces.event.FacesListener)
+ */
+ @Override
+ public void processListener(FacesListener listener) {
+ if (listener instanceof ValidatorListener) {
+ ValidatorListener validationListener = (ValidatorListener) listener;
+ validationListener.processValidation(this);
+ }
+
+ }
+
+}
Property changes on:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorEvent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorListener.java
===================================================================
---
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorListener.java
(rev 0)
+++
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorListener.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,34 @@
+/**
+ * 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.event;
+
+import javax.faces.event.FacesListener;
+
+
+/**
+ * @author asmirnov
+ *
+ */
+public interface ValidatorListener extends FacesListener {
+
+ public void processValidation(ValidatorEvent event);
+
+}
Property changes on:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/event/ValidatorListener.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java
===================================================================
---
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java
(rev 0)
+++
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,480 @@
+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.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.richfaces.component.ClonedObjectResolver;
+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";
+ protected 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";
+ private static final Object MUTEX = new Object();
+
+ private static final Log log = LogFactory.getLog(ObjectValidator.class);
+
+ protected final ObjectValidator parent;
+
+ /**
+ * Create BeanValidator instance. For a Junit tests only.
+ *
+ * @return
+ */
+ static ObjectValidator createInstance() {
+ // TODO - get instance class name from a "META-INF/service"
+ // If the Seam framework is active, org.jboss.seam.core.Validators
+ // component should be used.
+ ObjectValidator validator = null;
+ try {
+ validator = new BeanValidator();
+ } catch (Throwable e){
+ // JSR-303 is not avalable.
+ log.warn("Validator implementations not found at classpath, default
NullValidator will be used.");
+ validator = new NullValidator();
+ }
+ return validator;
+ }
+
+ 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) {
+ ExternalContext externalContext = context.getExternalContext();
+ externalContext.getContext();
+ ObjectValidator instance;
+ // TODO - use properly synchronization mutex ?
+ synchronized (MUTEX) {
+ Map<String, Object> applicationMap = externalContext
+ .getApplicationMap();
+ instance = (ObjectValidator) applicationMap.get(VALIDATOR_PARAM);
+ if (null == instance) {
+ // Vaildator not initialized - create and store new instance.
+ instance = createInstance();
+ applicationMap.put(VALIDATOR_PARAM, instance);
+ }
+ }
+ return instance;
+ }
+
+ 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
+ + ((locale == null) ? 0 : locale.hashCode());
+ result = prime
+ * result
+ + ((validatableClass == null) ? 0 : 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 (!(obj instanceof ValidatorKey))
+ return false;
+ ValidatorKey other = (ValidatorKey) obj;
+ if (locale == null) {
+ if (other.locale != null)
+ return false;
+ } else if (!locale.equals(other.locale))
+ return false;
+ if (validatableClass == null) {
+ if (other.validatableClass != null)
+ return false;
+ } else if (!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
Property changes on:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ObjectValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/RF-8742/ui/validator/impl/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/impl/pom.xml 2010-09-14 18:41:14 UTC (rev 19205)
+++ branches/RF-8742/ui/validator/impl/pom.xml 2010-09-14 22:30:39 UTC (rev 19206)
@@ -1,69 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
+ <!--
+ 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.
+ -->
-<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.richfaces.ui</groupId>
- <artifactId>richfaces-ui-parent</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- <relativePath>../../parent/pom.xml</relativePath>
- </parent>
+ <parent>
+ <groupId>org.richfaces.ui</groupId>
+ <artifactId>richfaces-ui-parent</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
- <groupId>org.richfaces.ui.validator</groupId>
- <artifactId>richfaces-ui-validator-impl</artifactId>
- <name>Richfaces UI Components: validator impl</name>
- <packaging>jar</packaging>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-checkstyle-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
+ <groupId>org.richfaces.ui.validator</groupId>
+ <artifactId>richfaces-ui-validator-impl</artifactId>
+ <name>Richfaces UI Components: validator impl</name>
+ <packaging>jar</packaging>
- <dependencies>
- <dependency>
- <!-- todo remove this dependency or move to test scope -->
- <groupId>org.richfaces.core</groupId>
- <artifactId>richfaces-core-impl</artifactId>
- </dependency>
- <dependency>
- <groupId>org.richfaces.ui.common</groupId>
- <artifactId>richfaces-ui-common-ui</artifactId>
- </dependency>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <!-- todo remove this dependency or move to test scope -->
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.ui.common</groupId>
+ <artifactId>richfaces-ui-common-ui</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.richfaces.ui.validator</groupId>
- <artifactId>richfaces-ui-validator-api</artifactId>
- </dependency>
- </dependencies>
-
- <scm>
-
<
connection>scm:svn:http://anonsvn.jboss.org/repos/richfaces/trunk/ui/v...
-
<
developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/trun...
- <
url>http://fisheye.jboss.org/browse/richfaces</url>
- </scm>
+
+ <dependency>
+ <groupId>org.richfaces.ui.validator</groupId>
+ <artifactId>richfaces-ui-validator-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>4.0.0.GA</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <scm>
+ <
connection>scm:svn:http://anonsvn.jboss.org/repos/richfaces/trunk/ui/v...
+ <
developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/trun...
+ <
url>http://fisheye.jboss.org/browse/richfaces</url>
+ </scm>
</project>
Property changes on: branches/RF-8742/ui/validator/impl/pom.xml
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Added:
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java
===================================================================
---
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java
(rev 0)
+++
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,163 @@
+/**
+ *
+ */
+package org.richfaces.validator;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Set;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.validation.ConstraintViolation;
+import javax.validation.MessageInterpolator;
+import javax.validation.Validation;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
+import javax.validation.ValidatorFactory;
+import javax.validation.groups.Default;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class BeanValidator extends ObjectValidator {
+
+ private static final Class[] DEFAULT_PROFILE = new Class[] {};
+ private final ValidatorFactory validatorFactory;
+ private ValidatorContext validatorContext;
+
+ BeanValidator() {
+ // Enforce class to load
+ ValidatorFactory.class.getName();
+ // Check Factory, to avoid instantiation errors
+ //
https://jira.jboss.org/jira/browse/RF-7226
+ validatorFactory = Validation
+ .buildDefaultValidatorFactory();
+ validatorContext = validatorFactory.usingContext();
+ MessageInterpolator jsfMessageInterpolator = new JsfMessageInterpolator(
+ validatorFactory.getMessageInterpolator());
+ validatorContext.messageInterpolator(jsfMessageInterpolator);
+ }
+
+ /*
+ * (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) {
+ Class beanType = base.getClass();
+ 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 = validatorContext.getValidator();
+ return beanValidator;
+ }
+
+ private static class JsfMessageInterpolator implements MessageInterpolator {
+
+ private MessageInterpolator delegate;
+
+ public JsfMessageInterpolator(
+ MessageInterpolator delegate) {
+ this.delegate = delegate;
+ }
+
+ public String interpolate(String messageTemplate, Context context) {
+
+ Locale locale = ObjectValidator.calculateLocale(FacesContext.getCurrentInstance());
+ if (null != locale) {
+ return delegate.interpolate(messageTemplate, context,
+ locale);
+ } else {
+ return delegate.interpolate(messageTemplate, context);
+ }
+ }
+
+ public String interpolate(String messageTemplate, Context context,
+ Locale locale) {
+ Locale faceslocale =
ObjectValidator.calculateLocale(FacesContext.getCurrentInstance());
+ if (null != faceslocale) {
+ return delegate.interpolate(messageTemplate, context,
+ faceslocale);
+ } else {
+ return delegate.interpolate(messageTemplate, context, locale);
+ }
+ }
+
+ }
+
+}
Property changes on:
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/BeanValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java
===================================================================
---
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java
(rev 0)
+++
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,181 @@
+/**
+ * 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.validator;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Set;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+
+/**
+ * Implementation of the JSF validator to use with Bean Validation / Hibernate
+ * validator
+ *
+ * @author asmirnov
+ *
+ */
+public class FacesBeanValidator implements NullValueValidator,Serializable,
GraphValidator {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -264568176252121853L;
+ public static final String BEAN_VALIDATOR_TYPE =
"org.richfaces.BeanValidator";
+
+ private ValueExpression summaryExpression = null;
+
+ private String summary = null;
+
+ private ValueExpression profilesExpression = null;
+
+ private Object profiles = null;
+ /**
+ * @return the summary
+ */
+ public String getSummary() {
+ String summaryString = null;
+ if(null != summaryExpression){
+ summaryString = (String)
summaryExpression.getValue(FacesContext.getCurrentInstance().getELContext());
+ }else {
+ summaryString = this.summary;
+ }
+ return summaryString;
+ }
+
+ /**
+ * @param summary the summary to set
+ */
+ public void setSummary(ValueExpression summary) {
+ this.summaryExpression = summary;
+ }
+
+
+ /**
+ * @param summary the summary to set
+ */
+ public void setSummary(String summary) {
+ this.summary = summary;
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.validator.Validator#validate(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent, java.lang.Object)
+ */
+ public void validate(FacesContext context, UIComponent component,
+ Object convertedValue) throws ValidatorException {
+ if (component instanceof EditableValueHolder) {
+ // Validate input component
+ EditableValueHolder input = (EditableValueHolder) component;
+ try {
+ ValueExpression valueExpression = component
+ .getValueExpression("value");
+ if (null != valueExpression) {
+ Collection<String> messages = ObjectValidator.getInstance(context)
+ .validate(context, valueExpression, convertedValue, getProfiles());
+ if (null != messages) {
+ input.setValid(false);
+ Object label = getLabel(context, component);
+ Locale locale = context.getViewRoot().getLocale();
+ // send all validation messages.
+ for (String msg : messages) {
+ //
https://jira.jboss.org/jira/browse/RF-7636 -
+ // format values.
+ msg = formatMessage(msg, locale, label,convertedValue); // create Summary message
?
+ String summaryString = getSummary() != null ? getSummary()
+ : msg;
+ summaryString = formatMessage(summaryString, locale, label,convertedValue);
+ context.addMessage(component.getClientId(context), new FacesMessage(
+ FacesMessage.SEVERITY_ERROR, summaryString , msg));
+ }
+ }
+ }
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+ }
+ }
+
+ static String formatMessage(String msg, Locale locale, Object... messageParams) {
+ if (msg.contains("{")) {
+ try {
+ MessageFormat messageFormat = new MessageFormat(
+ msg, locale);
+ msg = messageFormat.format(messageParams);
+ } catch (IllegalArgumentException e) {
+ // Do nothing, use original string unchanged.
+ }
+ }
+ return msg;
+ }
+
+ static Object getLabel(FacesContext context, UIComponent component) {
+ Object label = component.getAttributes().get("label");
+ if(null == label || 0 == label.toString().length()){
+ label = component.getClientId(context);
+ }
+ return label;
+ }
+
+ public Collection<String> validateGraph(FacesContext context, UIComponent
component,
+ Object value, Object profiles) throws ValidatorException {
+ ObjectValidator beanValidator = ObjectValidator.getInstance(context);
+ Collection<String> messages = beanValidator.validateGraph(context,
value,AjaxRendererUtils.asSet(profiles));
+ return messages;
+ }
+
+ /**
+ * @return the profiles
+ */
+ public Set<String> getProfiles() {
+ Object profiles;
+ if(null != profilesExpression){
+ profiles =
profilesExpression.getValue(FacesContext.getCurrentInstance().getELContext());
+ }else {
+ profiles = this.profiles;
+ }
+ return AjaxRendererUtils.asSet(profiles);
+ }
+
+ /**
+ * @param profiles the profiles to set
+ */
+ public void setProfiles(Object profiles) {
+ this.profiles = profiles;
+ }
+
+ public void setProfiles(ValueExpression profilesExpression) {
+ this.profilesExpression = profilesExpression;
+ }
+}
Property changes on:
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/FacesBeanValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/NullValidator.java
===================================================================
---
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/NullValidator.java
(rev 0)
+++
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/NullValidator.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+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;
+ }
+
+}
Property changes on:
branches/RF-8742/ui/validator/impl/src/main/java/org/richfaces/validator/NullValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Property changes on: branches/RF-8742/ui/validator/pom.xml
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Modified: branches/RF-8742/ui/validator/ui/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/ui/pom.xml 2010-09-14 18:41:14 UTC (rev 19205)
+++ branches/RF-8742/ui/validator/ui/pom.xml 2010-09-14 22:30:39 UTC (rev 19206)
@@ -56,6 +56,18 @@
<groupId>org.richfaces.ui.common</groupId>
<artifactId>richfaces-ui-common-ui</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>4.0.0.GA</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<scm>
Property changes on: branches/RF-8742/ui/validator/ui/pom.xml
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,34 @@
+/*
+ * $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.component;
+
+import javax.faces.component.behavior.ClientBehaviorBase;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class ClientValidatorBehavior extends ClientBehaviorBase {
+
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClonedObjectResolver.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClonedObjectResolver.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClonedObjectResolver.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,103 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.component.UIGraphValidator.GraphValidatorState;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ClonedObjectResolver extends ELResolver {
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getCommonPropertyType(javax.el.ELContext, java.lang.Object)
+ */
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base) {
+ // Do nothing
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getFeatureDescriptors(javax.el.ELContext, java.lang.Object)
+ */
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
+ Object base) {
+ // do nothing
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getType(javax.el.ELContext, java.lang.Object,
java.lang.Object)
+ */
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property) {
+ Object cloned = resolveCloned(context, base, property);
+ if(null != cloned){
+ context.setPropertyResolved(true);
+ return cloned.getClass();
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#getValue(javax.el.ELContext, java.lang.Object,
java.lang.Object)
+ */
+ @Override
+ public Object getValue(ELContext context, Object base, Object property) {
+ Object cloned = resolveCloned(context, base, property);
+ if(null != cloned){
+ context.setPropertyResolved(true);
+ }
+ return cloned;
+ }
+
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#isReadOnly(javax.el.ELContext, java.lang.Object,
java.lang.Object)
+ */
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.el.ELResolver#setValue(javax.el.ELContext, java.lang.Object,
java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void setValue(ELContext context, Object base, Object property,
+ Object value) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public static Object resolveCloned(ELContext context, Object base, Object property){
+ if(null != base || null != property){
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Map<String, Object> requestMap =
facesContext.getExternalContext().getRequestMap();
+ for (String key : requestMap.keySet()) {
+ if(null != key && key.startsWith(UIGraphValidator.STATE_ATTRIBUTE_PREFIX)){
+ UIGraphValidator.GraphValidatorState state = (GraphValidatorState)
requestMap.get(key);
+ if(state.isSame(base, property)){
+ return state.getCloned();
+ }
+ }
+ }
+ }
+ return null;
+ }
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClonedObjectResolver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,290 @@
+/**
+ * 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.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIMessage;
+import javax.faces.component.UIMessages;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+
+import org.ajax4jsf.component.AjaxComponent;
+import org.ajax4jsf.component.AjaxContainer;
+import org.ajax4jsf.component.AjaxSupport;
+import org.ajax4jsf.component.EventValueExpression;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.event.AjaxEvent;
+import org.ajax4jsf.event.AjaxListener;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.webapp.taglib.MethodExpressionAjaxListener;
+import org.richfaces.event.ValidatorEvent;
+
+/**
+ * JSF component class
+ *
+ */
+public abstract class UIAjaxValidator extends UIComponentBase implements
+ AjaxComponent, AjaxSupport, AjaxContainer {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.AjaxValidator";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.AjaxValidator";
+
+ public static final String BEAN_VALIDATOR_FACET = "org.richfaces.validator.";
+
+ @Override
+ public void setParent(UIComponent parent) {
+ super.setParent(parent);
+
+ if (null != parent && parent instanceof EditableValueHolder) {
+ setParentProperties(parent);
+ }
+ }
+
+ /**
+ * @param parent
+ * @throws FacesException
+ */
+ public void setParentProperties(UIComponent parent) throws FacesException {
+ if (!(parent instanceof EditableValueHolder)) {
+ throw new FacesException(
+ "Parent component must be an EditableValueHolder");
+ }
+
+ if (null != getEvent()) {
+ ValueExpression binding = new EventValueExpression(this);
+ parent.setValueExpression(getEvent(), binding);
+ }
+ }
+
+ @Override
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ super.broadcast(event);
+ if (event.getComponent() == this) {
+ FacesContext context = getFacesContext();
+ if (event instanceof ValidatorEvent) {
+ // ByPass UpdateModelValue
+ context.renderResponse();
+ } else if (event instanceof AjaxEvent) {
+ // TODO - find all UIMessages components for a parent UIInput.
+ // for an ajaxSingle component, re-render only target message.
+ AjaxContext ajaxContext = AjaxContext
+ .getCurrentInstance(context);
+ ajaxContext.setSubmittedRegionClientId(this
+ .getClientId(context));
+ }
+ }
+ }
+
+ @Override
+ public void queueEvent(FacesEvent event) {
+ if (event instanceof ValidatorEvent && event.getComponent() == this) {
+ UIComponent parent = getParent();
+ if (parent instanceof UIInput) {
+ UIInput input = (UIInput) parent;
+ if (input.isImmediate()) {
+ event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+ } else {
+ event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
+ }
+ }
+ }
+ super.queueEvent(event);
+ }
+
+ public String getEventString() {
+ StringBuffer buildOnEvent = new StringBuffer();
+ String onsubmit = getOnsubmit();
+ // Insert script to call before submit ajax request.
+ if (null != onsubmit) {
+ buildOnEvent.append(onsubmit).append(";");
+ }
+ buildOnEvent.append(AjaxRendererUtils.buildOnEvent(this,
+ getFacesContext(), getEvent(), true));
+ String script = buildOnEvent.toString();
+ return script;
+ }
+
+ public UIComponent getSingleComponent() {
+ return getParent();
+ }
+
+ public void encodeAjax(FacesContext context) throws IOException {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ Set<String> renderedAreas = ajaxContext.getAjaxRenderedAreas();
+ for (UIComponent message : getMessages(context)) {
+ if (message.isRendered()) {
+ message.encodeAll(context);
+ renderedAreas.add(message.getClientId(context));
+ }
+ }
+ // Write information about encoded areas after submission.
+ AjaxRendererUtils.encodeAreas(context, this);
+ }
+
+ public Set<UIComponent> getMessages(FacesContext context) {
+ Set<UIComponent> messages = new HashSet<UIComponent>();
+ findMessages(this.getParent(), this, messages,false);
+ findRichMessages(context, context.getViewRoot(), messages);
+ return messages;
+ }
+
+
+ /**
+ * Find all instances of the {@link UIRichMessages} and update list of the rendered
messages.
+ * @param context
+ * @param component
+ * @param messages
+ */
+ protected void findRichMessages(FacesContext context,UIComponent component,
Set<UIComponent> messages) {
+ Iterator<UIComponent> facetsAndChildren = component.getFacetsAndChildren();
+ while (facetsAndChildren.hasNext()) {
+ UIComponent child = (UIComponent) facetsAndChildren.next();
+ if (child instanceof UIRichMessages) {
+ UIRichMessages richMessage = (UIRichMessages) child;
+ if(null == richMessage.getFor()){
+ richMessage.updateMessages(context, this.getParent().getClientId(context));
+ messages.add(richMessage);
+ }
+ } else {
+ findRichMessages(context, child, messages);
+ }
+ }
+ }
+
+ /**
+ * Recursive search messages for the parent component.
+ * @param parent
+ * @param component
+ * @param messages
+ * @return
+ */
+ protected boolean findMessages(UIComponent parent, UIComponent component,
+ Set<UIComponent> messages,boolean found) {
+ Iterator<UIComponent> facetsAndChildren = parent.getFacetsAndChildren();
+ while (facetsAndChildren.hasNext()) {
+ UIComponent child = (UIComponent) facetsAndChildren.next();
+ if (child != component) {
+ if (child instanceof UIMessage || child instanceof UIMessages) {
+ UIComponent message = (UIComponent) child;
+ Object targetId = message.getAttributes().get("for");
+ if (null != targetId
+ && targetId.equals(getParent().getId())) {
+ messages.add(message);
+ found = true;
+ }
+ } else {
+ found |= findMessages(child, null, messages,found);
+ }
+ }
+ }
+ if(!(found && parent instanceof NamingContainer) && component !=
null){
+ UIComponent newParent = parent.getParent();
+ if(null != newParent){
+ found = findMessages(newParent, parent, messages,found);
+ }
+ }
+ return found;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.event.AjaxSource#addAjaxListener(org.ajax4jsf.event.AjaxListener
+ * )
+ */
+ public void addAjaxListener(AjaxListener listener) {
+ addFacesListener(listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.event.AjaxSource#getAjaxListeners()
+ */
+ public AjaxListener[] getAjaxListeners() {
+ return (AjaxListener[]) getFacesListeners(AjaxListener.class);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.ajax4jsf.event.AjaxSource#removeAjaxListener(org.ajax4jsf.event.
+ * AjaxListener)
+ */
+ public void removeAjaxListener(AjaxListener listener) {
+ removeFacesListener(listener);
+ }
+
+ public void setAjaxListener(MethodExpression listener) {
+ AjaxListener[] ajaxListeners = getAjaxListeners();
+ for (int i = 0; i < ajaxListeners.length; i++) {
+ AjaxListener ajaxListener = ajaxListeners[i];
+ if (ajaxListener.getClass().equals(
+ MethodExpressionAjaxListener.class)) {
+ MethodExpressionAjaxListener expressionListener = (MethodExpressionAjaxListener)
ajaxListener;
+ if (expressionListener.getExpression() != listener) {
+ removeAjaxListener(ajaxListener);
+
+ if (listener == null) {
+
+ return;
+ } else {
+
+ break;
+ }
+ }
+ }
+ }
+
+ addAjaxListener(new MethodExpressionAjaxListener(listener));
+ }
+
+ public MethodExpression getAjaxListener() {
+ AjaxListener[] ajaxListeners = getAjaxListeners();
+ for (int i = 0; i < ajaxListeners.length; i++) {
+ AjaxListener ajaxListener = ajaxListeners[i];
+ if (ajaxListener.getClass().equals(
+ MethodExpressionAjaxListener.class)) {
+ MethodExpressionAjaxListener expressionListener = (MethodExpressionAjaxListener)
ajaxListener;
+ return expressionListener.getExpression();
+ }
+ }
+
+ return null;
+ }
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIBeanValidator.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIBeanValidator.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIBeanValidator.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,23 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+/**
+ * Stage class to keep backward compatibility.
+ * @author asmirnov
+ * @deprecated That class has been renamed, Use {@link UIAjaxValidator} instead
+ *
+ */
+public abstract class UIBeanValidator extends UIAjaxValidator {
+
+ /* (non-Javadoc)
+ * @see javax.faces.component.UIComponent#getFamily()
+ */
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIBeanValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,377 @@
+/**
+ * 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.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+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.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIMessage;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.validator.Validator;
+
+import org.ajax4jsf.component.AjaxComponent;
+import org.ajax4jsf.component.AjaxContainer;
+import org.ajax4jsf.component.AjaxSupport;
+import org.ajax4jsf.component.EventValueExpression;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.el.ELContextWrapper;
+import org.ajax4jsf.event.AjaxEvent;
+import org.ajax4jsf.event.AjaxListener;
+import org.ajax4jsf.renderkit.AjaxContainerRenderer;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.util.CapturingELResolver;
+import org.richfaces.event.ValidatorEvent;
+import org.richfaces.validator.HibernateValidator;
+import org.richfaces.validator.FacesBeanValidator;
+import org.richfaces.validator.GraphValidator;
+
+
+/**
+ * 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";
+
+ public static final String STATE_ATTRIBUTE_PREFIX =
COMPONENT_TYPE+NamingContainer.SEPARATOR_CHAR;
+
+
+
+
+ /**
+ * 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 Object 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.cloned = method.invoke(value);
+ validatorState.base = capturingELResolver.getBase();
+ validatorState.property = capturingELResolver.getProperty();
+ validatorState.active = 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.active = 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 = 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.active = true;
+ }
+ super.processValidators(context);
+ if(null != validatorState){
+ validatorState.active = false;
+ validateObject(context, validatorState.cloned);
+ 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;
+ }
+
+ public static final class GraphValidatorState {
+ private boolean active = false;
+ private Object cloned;
+ private Object base;
+ private Object property;
+ /**
+ * @return the active
+ */
+ public boolean isActive() {
+ return active;
+ }
+ /**
+ * @param active the active to set
+ */
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+ /**
+ * @return the cloned
+ */
+ public Object getCloned() {
+ return cloned;
+ }
+ /**
+ * @param cloned the cloned to set
+ */
+ public void setCloned(Object cloned) {
+ this.cloned = cloned;
+ }
+ /**
+ * @return the base
+ */
+ public Object getBase() {
+ return base;
+ }
+ /**
+ * @param base the base to set
+ */
+ public void setBase(Object base) {
+ this.base = base;
+ }
+ /**
+ * @return the property
+ */
+ public Object getProperty() {
+ return property;
+ }
+ /**
+ * @param property the property to set
+ */
+ public void setProperty(Object property) {
+ this.property = property;
+ }
+
+ public boolean isSameBase(Object base){
+ return (null == base && null == this.base)||(base == this.base);
+ }
+
+ public boolean isSameProperty(Object property){
+ if(null == this.property){
+ return null == property;
+ } else {
+ return this.property.equals(property);
+ }
+ }
+
+ public boolean isSame(Object base, Object property){
+ return isSameBase(base)&& isSameProperty(property)&& active;
+ }
+ }
+
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIGraphValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,25 @@
+
+package org.richfaces.renderkit.html;
+
+
+//
+// Imports
+//
+import javax.faces.render.ClientBehaviorRenderer;
+
+
+
+/**
+ * Renderer for component class org.richfaces.renderkit.html.AjaxValidatorRenderer
+ */
+public class ClientValidatorRenderer extends ClientBehaviorRenderer {
+
+
+ public static final String RENDERER_TYPE =
"org.richfaces.ClientValidatorRenderer";
+ public ClientValidatorRenderer () {
+ super();
+ }
+
+
+
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,142 @@
+/**
+ * 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.taglib;
+
+import java.io.IOException;
+import java.util.Set;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.webapp.taglib.AjaxComponentHandler;
+import org.richfaces.component.UIAjaxValidator;
+import org.richfaces.validator.FacesBeanValidator;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.FaceletException;
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.TagException;
+import com.sun.facelets.tag.TagHandler;
+import com.sun.facelets.tag.jsf.ComponentConfig;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class AjaxValidatorHandler extends TagHandler {
+
+ /**
+ * A UIComponent for capturing a child UIComponent, representative of the
+ * desired Facet
+ *
+ * @author Jacob Hookom
+ *
+ */
+ private final static class UIFacet extends UIComponentBase {
+ public String getFamily() {
+ return null;
+ }
+ }
+
+ private TagAttribute _event;
+ private TagAttribute _summary;
+ private TagAttribute _profiles;
+ private AjaxComponentHandler _validatorHandler;
+
+ /**
+ * @param config
+ */
+ public AjaxValidatorHandler(ComponentConfig config) {
+ super(config);
+ _event = getAttribute("event");
+ _summary = getAttribute("summary");
+ _profiles = getAttribute("profiles");
+ _validatorHandler = new AjaxComponentHandler(config){
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ return
super.createMetaRuleset(type).ignore("summary").ignore("profiles");
+ }
+ };
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void apply(FaceletContext ctx, UIComponent parent)
+ throws IOException, FacesException, FaceletException, ELException {
+ if (parent == null || !(parent instanceof EditableValueHolder)) {
+ throw new TagException(this.tag,
+ "Parent not an instance of EditableValueHolder: " + parent);
+ }
+ if (null == parent.getParent()) {
+ // New created component, add validator.
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ FacesBeanValidator validator = (FacesBeanValidator) facesContext
+ .getApplication().createValidator(
+ FacesBeanValidator.BEAN_VALIDATOR_TYPE);
+ if (null != _summary) {
+ if (_summary.isLiteral()) {
+ validator.setSummary(_summary.getValue(ctx));
+
+ } else {
+ validator.setSummary(_summary.getValueExpression(ctx,
+ String.class));
+ }
+ }
+ if( null != _profiles){
+ if(_profiles.isLiteral()){
+ validator.setProfiles(_profiles.getValue());
+ } else {
+ validator.setProfiles(_profiles.getValueExpression(ctx, Set.class));
+ }
+ }
+ ((EditableValueHolder) parent).addValidator(validator);
+ }
+ if (null != this._event) {
+ UIComponent c;
+ UIFacet facet = new UIFacet();
+ // Find facet for client validation component
+ String eventName = _event.getValue();
+ String facetName = UIAjaxValidator.BEAN_VALIDATOR_FACET + eventName;
+ c = parent.getFacet(facetName);
+ if (null != c) {
+ parent.getFacets().remove(facetName);
+ facet.getChildren().add(c);
+ }
+ this._validatorHandler.apply(ctx, facet);
+ c = (UIComponent) facet.getChildren().get(0);
+ parent.getFacets().put(facetName, c);
+
+ }
+ }
+
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,150 @@
+/**
+ * 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.taglib;
+
+import javax.el.ValueExpression;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.webapp.UIComponentClassicTagBase;
+import javax.servlet.jsp.JspException;
+
+import org.ajax4jsf.webapp.taglib.UIComponentTagBase;
+import org.richfaces.component.UIAjaxValidator;
+import org.richfaces.renderkit.html.ClientValidatorRenderer;
+import org.richfaces.validator.FacesBeanValidator;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class AjaxValidatorTagBase extends UIComponentTagBase {
+
+ /**
+ * Generate script for given event ( onclick, onenter ... )
+ */
+ private String event = null;
+
+ private ValueExpression summary = null;
+
+ private ValueExpression profiles = null;
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentTagBase#getComponentType()
+ */
+ @Override
+ public String getComponentType() {
+ return UIAjaxValidator.COMPONENT_TYPE;
+ }
+
+ /**
+ * @param event
+ * the event to set
+ */
+ public void setEvent(String event) {
+ this.event = event;
+ }
+
+ /**
+ * @param summary
+ * the summary to set
+ */
+ public void setSummary(ValueExpression summary) {
+ this.summary = summary;
+ }
+
+ @Override
+ public int doStartTag() throws JspException {
+ // Locate our parent UIComponentTag
+ UIComponentClassicTagBase tag = UIComponentClassicTagBase
+ .getParentUIComponentClassicTagBase(pageContext);
+ if (tag == null) {
+ // PENDING i18n
+ throw new JspException(
+ "Not nested in a UIComponentTag Error for tag with handler class:"
+ + this.getClass().getName());
+ }
+ UIComponent component = tag.getComponentInstance();
+ if (!(component instanceof EditableValueHolder)) {
+ // PENDING i18n
+ throw new JspException(
+ "Not nested in a UIInput component. Error for tag with handler class:"
+ + this.getClass().getName());
+
+ }
+ // Nothing to do unless this tag created a component
+ if (tag.getCreated()) {
+ // New created component, add validator.
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ FacesBeanValidator validator = (FacesBeanValidator) facesContext
+ .getApplication().createValidator(
+ FacesBeanValidator.BEAN_VALIDATOR_TYPE);
+ if (null != summary) {
+ if(summary.isLiteralText()){
+ validator.setSummary(summary.getExpressionString());
+ } else {
+ validator.setSummary(summary);
+ }
+ }
+ if(null != profiles){
+ if(profiles.isLiteralText()){
+ validator.setProfiles(profiles.getExpressionString());
+ } else {
+ validator.setProfiles(profiles);
+ }
+ }
+ ((EditableValueHolder) component).addValidator(validator);
+
+ }
+ return super.doStartTag();
+ }
+
+ @Override
+ protected void setProperties(UIComponent component) {
+ super.setProperties(component);
+ setStringProperty(component, "event", event);
+ }
+
+ @Override
+ public void release() {
+ super.release();
+ event = null;
+ summary = null;
+ profiles = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentTagBase#getRendererType()
+ */
+ @Override
+ public String getRendererType() {
+ return ClientValidatorRenderer.RENDERER_TYPE;
+ }
+
+ @Override
+ protected String getFacetName() {
+ return UIAjaxValidator.BEAN_VALIDATOR_FACET
+ + (null == event ? "" : event);
+ }
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/AjaxValidatorTagBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorHandler.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorHandler.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorHandler.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,71 @@
+/**
+ * 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.taglib;
+
+import java.util.Set;
+
+import javax.faces.validator.Validator;
+
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.richfaces.validator.FacesBeanValidator;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.TagConfig;
+import com.sun.facelets.tag.jsf.ValidateHandler;
+import com.sun.facelets.tag.jsf.ValidatorConfig;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class BeanValidatorHandler extends ValidateHandler {
+
+
+ private TagAttribute _profiles;
+
+
+
+ /**
+ * @param config
+ */
+ public BeanValidatorHandler(ValidatorConfig config) {
+ super(config);
+ _profiles = getAttribute("profiles");
+ }
+
+ @Override
+ protected Validator createValidator(FaceletContext ctx) {
+ FacesBeanValidator validator = (FacesBeanValidator) ctx.getFacesContext()
+ .getApplication().createValidator(
+ FacesBeanValidator.BEAN_VALIDATOR_TYPE);
+ if(null != _profiles){
+ if(_profiles.isLiteral()){
+ validator.setProfiles(AjaxRendererUtils.asSet(_profiles.getValue()));
+ } else {
+ validator.setProfiles(_profiles.getValueExpression(ctx, Set.class));
+ }
+ }
+ return validator;
+ }
+
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorTag.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorTag.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorTag.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,139 @@
+/**
+ * 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.taglib;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.servlet.jsp.JspException;
+
+import org.richfaces.validator.HibernateValidator;
+import org.richfaces.validator.FacesBeanValidator;
+
+public class BeanValidatorTag extends javax.faces.webapp.ValidatorELTag {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5230299574915210593L;
+ // Fields
+
+ /*
+ * summary Summary message for a validation errors.
+ */
+ private ValueExpression _summary;
+
+ /**
+ * <p>The {@link javax.el.ValueExpression} that evaluates to an object that
+ * implements {@link HibernateValidator}.</p>
+ */
+ private ValueExpression binding = null;
+
+
+ private ValueExpression profiles = null;
+
+ /**
+ * Summary message for a validation errors. Setter for summary
+ *
+ * @param summary
+ * - new value
+ */
+ public void setSummary(ValueExpression __summary) {
+ this._summary = __summary;
+ }
+
+ /**
+ * <p>Set the expression that will be used to create a
+ * {@link javax.el.ValueExpression} that references a backing bean property
+ * of the {@link HibernateValidator} instance to be created.</p>
+ *
+ * @param binding The new expression
+ */
+ public void setBinding(ValueExpression binding) {
+ this.binding = binding;
+ }
+
+ /**
+ * @param profiles the profiles to set
+ */
+ public void setProfiles(ValueExpression profiles) {
+ this.profiles = profiles;
+ }
+
+ protected Validator createValidator() throws JspException {
+ ValueExpression ve = this.binding;
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ FacesBeanValidator validator = null;
+
+ try {
+ ELContext elContext = facesContext.getELContext();
+ if (ve != null) {
+ validator = (FacesBeanValidator) ve.getValue(elContext);
+ }
+
+ if (validator == null) {
+ validator = (FacesBeanValidator) FacesContext
+ .getCurrentInstance().getApplication().createValidator(
+ "org.richfaces.BeanValidator");
+
+ if (ve != null && validator != null) {
+ ve.setValue(elContext, validator);
+ }
+ }
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+
+ _setProperties(validator);
+
+ return validator;
+ }
+
+ @Override
+ public void release() {
+ this.binding = null;
+ this._summary = null;
+ this.profiles = null;
+ super.release();
+ }
+ // Support method to wire in properties
+ private void _setProperties(FacesBeanValidator validator)
+ throws JspException {
+ if (_summary != null) {
+ if (_summary.isLiteralText()) {
+ validator.setSummary(_summary.getExpressionString());
+ } else {
+ validator.setSummary(_summary);
+ }
+ }
+ if(null != profiles){
+ if(profiles.isLiteralText()){
+ validator.setProfiles(profiles.getExpressionString());
+ } else {
+ validator.setProfiles(profiles);
+ }
+ }
+ }
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/BeanValidatorTag.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/GraphValidatorHandler.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/GraphValidatorHandler.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/GraphValidatorHandler.java 2010-09-14
22:30:39 UTC (rev 19206)
@@ -0,0 +1,57 @@
+/**
+ *
+ */
+package org.richfaces.taglib;
+
+import java.util.Set;
+
+import javax.faces.component.UIComponent;
+
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.richfaces.component.UIGraphValidator;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.jsf.ComponentConfig;
+import com.sun.facelets.tag.jsf.ComponentHandler;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class GraphValidatorHandler extends ComponentHandler {
+
+ private TagAttribute _profiles;
+
+ /**
+ * @param config
+ */
+ public GraphValidatorHandler(ComponentConfig config) {
+ super(config);
+ _profiles = getAttribute("profiles");
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ return super.createMetaRuleset(type).ignore("profiles");
+ }
+
+
+ @Override
+ protected void onComponentCreated(FaceletContext ctx, UIComponent c,
+ UIComponent parent) {
+ super.onComponentCreated(ctx, c, parent);
+ if (c instanceof UIGraphValidator) {
+ UIGraphValidator graphValidator = (UIGraphValidator) c;
+ if(null != _profiles){
+ if (_profiles.isLiteral()) {
+ graphValidator.setProfiles(AjaxRendererUtils.asSet(_profiles.getValue()));
+ } else {
+ graphValidator.setValueExpression("profiles",
_profiles.getValueExpression(ctx, Set.class));
+ }
+ }
+
+ }
+ }
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/taglib/GraphValidatorHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain