You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ba...@apache.org on 2006/10/26 13:18:50 UTC
svn commit: r467959 - in /myfaces/core/branches/jsf12:
api/src/main/java/javax/faces/webapp/ValidatorELTag.java
impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorTag.java
Author: baranda
Date: Thu Oct 26 04:18:49 2006
New Revision: 467959
URL: http://svn.apache.org/viewvc?view=rev&rev=467959
Log:
Applied patch for MYFACES-1475 (JSR-252 ValidatorTag). Thanks to Andreas Berger
Added:
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorTag.java (with props)
Modified:
myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/ValidatorELTag.java
Modified: myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/ValidatorELTag.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/ValidatorELTag.java?view=diff&rev=467959&r1=467958&r2=467959
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/ValidatorELTag.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/ValidatorELTag.java Thu Oct 26 04:18:49 2006
@@ -15,32 +15,21 @@
*/
package javax.faces.webapp;
-import javax.servlet.jsp.tagext.TagSupport;
-import javax.servlet.jsp.tagext.Tag;
-import javax.servlet.jsp.JspException;
-import javax.faces.validator.Validator;
-import javax.faces.component.UIComponent;
import javax.faces.component.EditableValueHolder;
-import javax.faces.context.FacesContext;
-import javax.faces.application.Application;
-import javax.faces.el.ValueBinding;
+import javax.faces.component.UIComponent;
+import javax.faces.validator.Validator;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.Tag;
+import javax.servlet.jsp.tagext.TagSupport;
/**
- * see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/api/index.html">JSF Specification</a>
- *
* @author Manfred Geiler (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class ValidatorELTag
+public abstract class ValidatorELTag
extends TagSupport
{
private static final long serialVersionUID = 8794036166323016663L;
- private String _validatorId;
-
- public void setValidatorId(String validatorId)
- {
- _validatorId = validatorId;
- }
public int doStartTag()
throws javax.servlet.jsp.JspException
@@ -64,32 +53,14 @@
}
if (!(component instanceof EditableValueHolder))
{
- throw new JspException("UIComponent is no ValueHolder");
+ throw new JspException("UIComponent is no EditableValueHolder");
}
((EditableValueHolder)component).addValidator(validator);
return Tag.SKIP_BODY;
}
- public void release()
- {
- super.release();
- _validatorId = null;
- }
+ protected abstract Validator createValidator()
+ throws JspException;
- protected Validator createValidator()
- throws JspException
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- Application application = facesContext.getApplication();
- if (UIComponentTag.isValueReference(_validatorId))
- {
- ValueBinding vb = facesContext.getApplication().createValueBinding(_validatorId);
- return application.createValidator((String)vb.getValue(facesContext));
- }
- else
- {
- return application.createValidator(_validatorId);
- }
- }
}
Added: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorTag.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorTag.java?view=auto&rev=467959
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorTag.java (added)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorTag.java Thu Oct 26 04:18:49 2006
@@ -0,0 +1,115 @@
+/*
+* Copyright 2004-2006 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.myfaces.taglib.core;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.application.Application;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.webapp.ValidatorELTag;
+import javax.servlet.jsp.JspException;
+
+/**
+ * Basic Validator implementation.
+ *
+ * @author Andreas Berger (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class ValidatorTag
+ extends ValidatorELTag
+{
+ private ValueExpression _validatorId;
+ private ValueExpression _binding;
+ private String _validatorIdString = null;
+
+ public void setValidatorId(ValueExpression validatorId)
+ {
+ _validatorId = validatorId;
+ }
+
+ public void setBinding(ValueExpression binding)
+ {
+ _binding = binding;
+ }
+
+ /**
+ * Use this method to specify the validatorId programmatically.
+ *
+ * @param validatorIdString
+ */
+ public void setValidatorIdString(String validatorIdString)
+ {
+ _validatorIdString = validatorIdString;
+ }
+
+ public void release()
+ {
+ super.release();
+ _validatorId = null;
+ _binding = null;
+ _validatorIdString = null;
+ }
+
+ protected Validator createValidator() throws javax.servlet.jsp.JspException
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ ELContext elContext = facesContext.getELContext();
+ if (null != _binding)
+ {
+ Object validator;
+ try
+ {
+ validator = _binding.getValue(elContext);
+ } catch (Exception e)
+ {
+ throw new JspException("Error while creating the Validator", e);
+ }
+ if (validator instanceof Validator)
+ {
+ return (Validator) validator;
+ }
+ }
+ Application application = facesContext.getApplication();
+ Validator validator = null;
+ try
+ {
+ // first check if an ValidatorId was set by a method
+ if (null != _validatorIdString)
+ {
+ validator = application.createValidator(_validatorIdString);
+ } else if (null != _validatorId)
+ {
+ String validatorId = (String) _validatorId.getValue(elContext);
+ validator = application.createValidator(validatorId);
+ }
+ } catch (Exception e)
+ {
+ throw new JspException("Error while creating the Validator", e);
+ }
+
+ if (null != validator)
+ {
+ if (null != _binding)
+ {
+ _binding.setValue(elContext, validator);
+ }
+ return validator;
+ }
+ throw new JspException("validatorId and/or binding must be specified");
+ }
+
+}
Propchange: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL