Coverage Report - org.apache.tapestry.form.TextField
 
Classes in this File Line Coverage Branch Coverage Complexity
TextField
0%
0/32
0%
0/10
1.6
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.form;
 16  
 
 17  
 import org.apache.tapestry.*;
 18  
 import org.apache.tapestry.valid.ValidatorException;
 19  
 
 20  
 import java.util.HashMap;
 21  
 import java.util.Map;
 22  
 
 23  
 /**
 24  
  * Implements a component that manages an HTML <input type=text> or
 25  
  * &lt;input type=password&gt; form element. [ <a
 26  
  * href="../../../../../components/form/textfield.html">Component Reference
 27  
  * </a>]
 28  
  * <p>
 29  
  * As of 4.0, this component can be configurably translated and validated.
 30  
  * 
 31  
  * @author Howard Lewis Ship
 32  
  * @author Paul Ferraro
 33  
  */
 34  0
 public abstract class TextField extends AbstractFormComponent implements TranslatedField
 35  
 {
 36  
 
 37  
     public abstract boolean isHidden();
 38  
 
 39  
     public abstract Object getValue();
 40  
 
 41  
     public abstract void setValue(Object value);
 42  
 
 43  
     public abstract String getMask();
 44  
     
 45  
     /**
 46  
      * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter,
 47  
      *      org.apache.tapestry.IRequestCycle)
 48  
      */
 49  
     protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 50  
     {
 51  0
         String value = getTranslatedFieldSupport().format(this, getValue());
 52  
         
 53  0
         renderDelegatePrefix(writer, cycle);
 54  
 
 55  0
         writer.beginEmpty("input");
 56  
 
 57  0
         writer.attribute("type", isHidden() ? "password" : "text");
 58  
 
 59  0
         writer.attribute("name", getName());
 60  
 
 61  0
         if (isDisabled()) 
 62  0
             writer.attribute("disabled", "disabled");
 63  
 
 64  0
         if (value != null) 
 65  0
             writer.attribute("value", value);
 66  
 
 67  0
         renderIdAttribute(writer, cycle);
 68  
 
 69  0
         renderDelegateAttributes(writer, cycle);
 70  
 
 71  0
         getTranslatedFieldSupport().renderContributions(this, writer, cycle);
 72  0
         getValidatableFieldSupport().renderContributions(this, writer, cycle);
 73  
 
 74  0
         renderInformalParameters(writer, cycle);
 75  
         
 76  0
         writer.closeTag();
 77  
 
 78  0
         renderDelegateSuffix(writer, cycle);
 79  
 
 80  0
         if (isParameterBound("mask") && !isDisabled())
 81  
         {
 82  0
             PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
 83  
 
 84  0
             Map symbols = new HashMap();
 85  0
             symbols.put("field", this);
 86  
             
 87  0
             getMaskScript().execute(this, cycle, pageRenderSupport, symbols);
 88  
         }
 89  0
     }
 90  
 
 91  
     /**
 92  
      * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter,
 93  
      *      org.apache.tapestry.IRequestCycle)
 94  
      */
 95  
     protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 96  
     {
 97  0
         String value = cycle.getParameter(getName());
 98  
 
 99  
         try
 100  
         {
 101  0
             Object object = getTranslatedFieldSupport().parse(this, value);
 102  
 
 103  0
             getValidatableFieldSupport().validate(this, writer, cycle, object);
 104  
 
 105  0
             setValue(object);
 106  
         }
 107  0
         catch (ValidatorException e)
 108  
         {
 109  0
             getForm().getDelegate().record(e);
 110  0
         }
 111  0
     }
 112  
 
 113  
     /**
 114  
      * Injected.
 115  
      *
 116  
      * @return The Validation service.
 117  
      */
 118  
     public abstract ValidatableFieldSupport getValidatableFieldSupport();
 119  
 
 120  
     /**
 121  
      * Injected.
 122  
      *
 123  
      * @return The translator service.
 124  
      */
 125  
     public abstract TranslatedFieldSupport getTranslatedFieldSupport();
 126  
 
 127  
     /**
 128  
      * Injected mask editing script.
 129  
      * @return The local mask script template.
 130  
      */
 131  
     public abstract IScript getMaskScript();
 132  
 
 133  
     /**
 134  
      * @see org.apache.tapestry.form.AbstractFormComponent#isRequired()
 135  
      */
 136  
     public boolean isRequired()
 137  
     {
 138  0
         return getValidatableFieldSupport().isRequired(this);
 139  
     }
 140  
 }