Coverage Report - javax.faces.webapp.ValidatorTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidatorTag
0%
0/36
0%
0/20
4.2
 
 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  
  * @author Manfred Geiler (latest modification by $Author: skitching $)
 35  
  * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Sun, 13 Jul 2008) $
 36  
  *
 37  
  * @deprecated replaced by {@link ValidatorELTag}
 38  
  */
 39  0
 public class ValidatorTag
 40  
         extends TagSupport
 41  
 {
 42  
     private static final long serialVersionUID = 8794036166323016663L;
 43  
     private String _validatorId;
 44  
     private String _binding;
 45  
 
 46  
     public void setValidatorId(String validatorId)
 47  
     {
 48  0
         _validatorId = validatorId;
 49  0
     }
 50  
 
 51  
     public int doStartTag()
 52  
             throws javax.servlet.jsp.JspException
 53  
     {
 54  0
         UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext);
 55  0
         if (componentTag == null)
 56  
         {
 57  0
             throw new JspException("no parent UIComponentTag found");
 58  
         }
 59  0
         if (!componentTag.getCreated())
 60  
         {
 61  0
             return Tag.SKIP_BODY;
 62  
         }
 63  
 
 64  0
         Validator validator = createValidator();
 65  
 
 66  0
         UIComponent component = componentTag.getComponentInstance();
 67  0
         if (component == null)
 68  
         {
 69  0
             throw new JspException("parent UIComponentTag has no UIComponent");
 70  
         }
 71  0
         if (!(component instanceof EditableValueHolder))
 72  
         {
 73  0
             throw new JspException("UIComponent is no ValueHolder");
 74  
         }
 75  0
         ((EditableValueHolder)component).addValidator(validator);
 76  
 
 77  0
         return Tag.SKIP_BODY;
 78  
     }
 79  
 
 80  
     public void release()
 81  
     {
 82  0
         super.release();
 83  0
         _validatorId = null;
 84  0
         _binding = null;
 85  0
     }
 86  
 
 87  
     protected Validator createValidator()
 88  
             throws JspException
 89  
     {
 90  0
         FacesContext facesContext = FacesContext.getCurrentInstance();
 91  0
         Application application = facesContext.getApplication();
 92  
         
 93  0
         if(_binding != null) {
 94  0
             ValueBinding vb = application.createValueBinding(_binding);
 95  0
             if(vb != null) {
 96  0
                 Validator validator = (Validator) vb.getValue(facesContext);
 97  0
                 if(validator != null) {
 98  0
                     return validator;
 99  
                 }
 100  
             }
 101  
         }
 102  
         
 103  0
         if (UIComponentTag.isValueReference(_validatorId))
 104  
         {
 105  0
             ValueBinding vb = facesContext.getApplication().createValueBinding(_validatorId);
 106  0
             return application.createValidator((String)vb.getValue(facesContext));
 107  
         }
 108  
 
 109  0
         return application.createValidator(_validatorId);
 110  
         
 111  
     }
 112  
     
 113  
     /**
 114  
      * 
 115  
      * @param binding
 116  
      * @throws javax.servlet.jsp.JspException
 117  
      * 
 118  
      * @deprecated
 119  
      */
 120  
     public void setBinding(java.lang.String binding)
 121  
             throws javax.servlet.jsp.JspException
 122  
     {
 123  0
         if (binding != null && !UIComponentTag.isValueReference(binding))
 124  
         {
 125  0
             throw new IllegalArgumentException("not a valid binding: " + binding);
 126  
         }
 127  0
         _binding = binding;
 128  0
     }
 129  
 }