You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2006/06/17 04:45:31 UTC

svn commit: r414987 - /myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/ValidatorELTag.java

Author: dennisbyrne
Date: Fri Jun 16 19:45:30 2006
New Revision: 414987

URL: http://svn.apache.org/viewvc?rev=414987&view=rev
Log:
implmented ValidatorELTag

Added:
    myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/ValidatorELTag.java

Added: 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?rev=414987&view=auto
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/ValidatorELTag.java (added)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/ValidatorELTag.java Fri Jun 16 19:45:30 2006
@@ -0,0 +1,71 @@
+package javax.faces.webapp;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.validator.Validator;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author Dennis Byrne
+ * @since 1.2
+ */
+
+public abstract class ValidatorELTag extends TagSupport
+{
+
+    private static final Log log = LogFactory.getLog(ValidatorELTag.class);
+
+    public int doStartTag() throws JspException
+    {
+
+        if (log.isInfoEnabled())
+            log.info("JSF 1.2 SPEC : Create a new instance "
+                    + "of the specified Validator");
+
+        Validator validator = createValidator();
+
+        if (validator == null)
+            throw new JspException("Could not create a Validator");
+
+        if (log.isInfoEnabled())
+            log.info(" ... and register it with the UIComponent "
+                    + "instance associated with our most "
+                    + "immediately surrounding UIComponentTagBase");
+
+        UIComponentTagBase tag = UIComponentELTag
+                .getParentUIComponentClassicTagBase(pageContext);
+
+        if (tag == null)
+            throw new JspException(
+                    "Could not obtain reference to parent UIComponentClassicTagBase instance ");
+
+        if (log.isInfoEnabled())
+            log.info(" ... if the UIComponent instance was created "
+                    + "by this execution of the containing JSP page.");
+
+        if (tag.getCreated())
+        {
+
+            UIComponent component = tag.getComponentInstance();
+
+            if (component == null)
+                throw new JspException(
+                        "Could not obtain reference to UIComponent for parent UIComponentClassicTagBase instance ");
+
+            if (!(component instanceof EditableValueHolder))
+                throw new JspException(
+                        "UIComponent is not a EditableValueHolder " + component);
+
+            ((EditableValueHolder) component).addValidator(validator);
+        }
+
+        return SKIP_BODY;
+    }
+    
+    protected abstract Validator createValidator() throws JspException;
+    
+}