Coverage Report - javax.faces.webapp.ValidatorTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidatorTag
31%
8/26
10%
1/10
3
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package javax.faces.webapp;
 17  
 
 18  
 import javax.faces.component.EditableValueHolder;
 19  
 import javax.faces.component.UIComponent;
 20  
 import javax.faces.internal.WebAppUtil;
 21  
 import javax.faces.validator.Validator;
 22  
 import javax.servlet.jsp.JspException;
 23  
 import javax.servlet.jsp.tagext.TagSupport;
 24  
 
 25  
 /**
 26  
  * @author shot
 27  
  */
 28  
 public class ValidatorTag extends TagSupport {
 29  
 
 30  
     private static final long serialVersionUID = 1L;
 31  
 
 32  21
     private String validatorId = null;
 33  
 
 34  21
     public ValidatorTag() {
 35  21
     }
 36  
 
 37  
     public void setValidatorId(String validatorId) {
 38  21
         this.validatorId = validatorId;
 39  21
     }
 40  
 
 41  
     public int doStartTag() throws JspException {
 42  0
         UIComponentTag tag = UIComponentTag
 43  
                 .getParentUIComponentTag(pageContext);
 44  0
         if (tag == null) {
 45  0
             throw new JspException("Not nested in a UIComponentTag");
 46  
         }
 47  0
         if (!tag.getCreated()) {
 48  0
             return EVAL_PAGE;
 49  
         }
 50  0
         Validator validator = createValidator();
 51  0
         UIComponent component = tag.getComponentInstance();
 52  0
         if (component == null || !(component instanceof EditableValueHolder)) {
 53  0
             throw new JspException(
 54  
                     "Component is null or not editable value holder.");
 55  
         }
 56  0
         EditableValueHolder editableValueHolder = (EditableValueHolder) component;
 57  0
         editableValueHolder.addValidator(validator);
 58  0
         return SKIP_BODY;
 59  
     }
 60  
 
 61  
     public void release() {
 62  0
         validatorId = null;
 63  0
         super.release();
 64  0
     }
 65  
 
 66  
     protected Validator createValidator() throws JspException {
 67  
         try {
 68  21
             String id = this.validatorId;
 69  21
             if (UIComponentTag.isValueReference(id)) {
 70  0
                 id = (String) WebAppUtil.getValueFromCreatedValueBinding(id);
 71  
             }
 72  21
             return WebAppUtil.createValidator(id);
 73  0
         } catch (Exception e) {
 74  0
             throw new JspException(e);
 75  
         }
 76  
     }
 77  
 }