You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/04/21 23:59:22 UTC

svn commit: r767311 - /myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/taglib/core/ValidateRequiredTag.java

Author: lu4242
Date: Tue Apr 21 21:59:21 2009
New Revision: 767311

URL: http://svn.apache.org/viewvc?rev=767311&view=rev
Log:
MYFACES-2163 Add RequiredValidator Tag class (not generated!)

Added:
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/taglib/core/ValidateRequiredTag.java   (with props)

Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/taglib/core/ValidateRequiredTag.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/taglib/core/ValidateRequiredTag.java?rev=767311&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/taglib/core/ValidateRequiredTag.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/taglib/core/ValidateRequiredTag.java Tue Apr 21 21:59:21 2009
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.RequiredValidator;
+import javax.faces.validator.Validator;
+import javax.faces.webapp.ValidatorELTag;
+import javax.servlet.jsp.JspException;
+
+/**
+ * JSP Tag class for {@link javax.faces.validator.RequiredValidator}.
+ *
+ * @author Leonardo Uribe
+ * @since 2.0
+ */
+public class ValidateRequiredTag extends ValidatorELTag
+{
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 6569308536432242026L;
+        
+    private ValueExpression _binding;
+    
+    public void setBinding(ValueExpression binding)
+    {
+        _binding = binding;
+    }
+
+    @Override
+    public void release()
+    {
+        _binding = null;
+    }
+    
+    @Override
+    protected Validator createValidator() throws 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
+        {
+            validator = application.createValidator(RequiredValidator.VALIDATOR_ID);
+        }
+        catch (Exception e)
+        {
+            throw new JspException("Error while creating the Validator", e);
+        }
+
+        if (null != validator)
+        {
+            if (null != _binding)
+            {
+                _binding.setValue(elContext, validator);
+            }            
+        }
+        return validator;
+    }
+}

Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/taglib/core/ValidateRequiredTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/taglib/core/ValidateRequiredTag.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL