Coverage Report - javax.faces.webapp.ValidatorTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidatorTag
0%
0/36
0%
0/20
4.4
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package javax.faces.webapp;
 20  
 
 21  
 import javax.faces.application.Application;
 22  
 import javax.faces.component.EditableValueHolder;
 23  
 import javax.faces.component.UIComponent;
 24  
 import javax.faces.context.FacesContext;
 25  
 import javax.faces.el.ValueBinding;
 26  
 import javax.faces.validator.Validator;
 27  
 import javax.servlet.jsp.JspException;
 28  
 import javax.servlet.jsp.tagext.Tag;
 29  
 import javax.servlet.jsp.tagext.TagSupport;
 30  
 
 31  
 /**
 32  
  * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
 33  
  * 
 34  
  * @deprecated replaced by {@link ValidatorELTag}
 35  
  */
 36  0
 public class ValidatorTag extends TagSupport
 37  
 {
 38  
     private static final long serialVersionUID = 8794036166323016663L;
 39  
     private String _validatorId;
 40  
     private String _binding;
 41  
 
 42  
     public void setValidatorId(String validatorId)
 43  
     {
 44  0
         _validatorId = validatorId;
 45  0
     }
 46  
 
 47  
     @Override
 48  
     public int doStartTag() throws JspException
 49  
     {
 50  0
         UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext);
 51  0
         if (componentTag == null)
 52  
         {
 53  0
             throw new JspException("no parent UIComponentTag found");
 54  
         }
 55  0
         if (!componentTag.getCreated())
 56  
         {
 57  0
             return Tag.SKIP_BODY;
 58  
         }
 59  
 
 60  0
         Validator validator = createValidator();
 61  
 
 62  0
         UIComponent component = componentTag.getComponentInstance();
 63  0
         if (component == null)
 64  
         {
 65  0
             throw new JspException("parent UIComponentTag has no UIComponent");
 66  
         }
 67  0
         if (!(component instanceof EditableValueHolder))
 68  
         {
 69  0
             throw new JspException("UIComponent is no ValueHolder");
 70  
         }
 71  0
         ((EditableValueHolder)component).addValidator(validator);
 72  
 
 73  0
         return Tag.SKIP_BODY;
 74  
     }
 75  
 
 76  
     @Override
 77  
     public void release()
 78  
     {
 79  0
         super.release();
 80  0
         _validatorId = null;
 81  0
         _binding = null;
 82  0
     }
 83  
 
 84  
     /**
 85  
      * @throws JspException  
 86  
      */
 87  
     protected Validator createValidator() throws JspException
 88  
     {
 89  0
         FacesContext facesContext = FacesContext.getCurrentInstance();
 90  0
         Application application = facesContext.getApplication();
 91  
 
 92  0
         if (_binding != null)
 93  
         {
 94  0
             ValueBinding vb = application.createValueBinding(_binding);
 95  0
             if (vb != null)
 96  
             {
 97  0
                 Validator validator = (Validator)vb.getValue(facesContext);
 98  0
                 if (validator != null)
 99  
                 {
 100  0
                     return validator;
 101  
                 }
 102  
             }
 103  
         }
 104  
 
 105  0
         if (UIComponentTag.isValueReference(_validatorId))
 106  
         {
 107  0
             ValueBinding vb = facesContext.getApplication().createValueBinding(_validatorId);
 108  0
             return application.createValidator((String)vb.getValue(facesContext));
 109  
         }
 110  
 
 111  0
         return application.createValidator(_validatorId);
 112  
 
 113  
     }
 114  
 
 115  
     /**
 116  
      * 
 117  
      * @param binding
 118  
      * @throws javax.servlet.jsp.JspException
 119  
      * 
 120  
      * @deprecated
 121  
      */
 122  
     public void setBinding(java.lang.String binding) throws javax.servlet.jsp.JspException
 123  
     {
 124  0
         if (binding != null && !UIComponentTag.isValueReference(binding))
 125  
         {
 126  0
             throw new IllegalArgumentException("not a valid binding: " + binding);
 127  
         }
 128  0
         _binding = binding;
 129  0
     }
 130  
 }