Author: nbelaevski
Date: 2008-08-30 18:44:13 -0400 (Sat, 30 Aug 2008)
New Revision: 10249
Modified:
trunk/ui/beanValidator/src/main/config/component/beanValidator.xml
trunk/ui/beanValidator/src/main/java/org/richfaces/taglib/BeanValidatorTag.java
Log:
https://jira.jboss.org/jira/browse/RF-4082
Modified: trunk/ui/beanValidator/src/main/config/component/beanValidator.xml
===================================================================
--- trunk/ui/beanValidator/src/main/config/component/beanValidator.xml 2008-08-30 15:28:43
UTC (rev 10248)
+++ trunk/ui/beanValidator/src/main/config/component/beanValidator.xml 2008-08-30 22:44:13
UTC (rev 10249)
@@ -137,5 +137,13 @@
Summary message for a validation errors.
</description>
</property>
+ <property exist="true">
+ <name>binding</name>
+ <classname>org.richfaces.validator.FacesBeanValidator</classname>
+ <description>
+ A ValueExpression that evaluates to an instance of
+ FacesBeanValidator.
+ </description>
+ </property>
</validator>
</components>
Modified: trunk/ui/beanValidator/src/main/java/org/richfaces/taglib/BeanValidatorTag.java
===================================================================
---
trunk/ui/beanValidator/src/main/java/org/richfaces/taglib/BeanValidatorTag.java 2008-08-30
15:28:43 UTC (rev 10248)
+++
trunk/ui/beanValidator/src/main/java/org/richfaces/taglib/BeanValidatorTag.java 2008-08-30
22:44:13 UTC (rev 10249)
@@ -3,11 +3,14 @@
*/
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.BeanValidator;
import org.richfaces.validator.FacesBeanValidator;
public class BeanValidatorTag extends javax.faces.webapp.ValidatorELTag {
@@ -23,7 +26,13 @@
*/
private ValueExpression _summary;
- /**
+ /**
+ * <p>The {@link javax.el.ValueExpression} that evaluates to an object that
+ * implements {@link BeanValidator}.</p>
+ */
+ private ValueExpression binding = null;
+
+ /**
* Summary message for a validation errors. Setter for summary
*
* @param summary
@@ -33,11 +42,45 @@
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 BeanValidator} instance to be created.</p>
+ *
+ * @param binding The new expression
+ */
+ public void setBinding(ValueExpression binding) {
+ this.binding = binding;
+ }
+
protected Validator createValidator() throws JspException {
- FacesBeanValidator validator = (FacesBeanValidator) FacesContext
- .getCurrentInstance().getApplication().createValidator(
- "org.richfaces.BeanValidator");
+ 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;
}