Clover coverage report - Code Coverage for tapestry release 4.0-rc-2
Coverage timestamp: Sat Dec 17 2005 09:39:46 PST
file stats: LOC: 111   Methods: 3
NCLOC: 48   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TextField.java 83.3% 100% 100% 96.9%
coverage coverage
 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.IMarkupWriter;
 18    import org.apache.tapestry.IRequestCycle;
 19    import org.apache.tapestry.valid.ValidatorException;
 20   
 21    /**
 22    * Implements a component that manages an HTML <input type=text> or <input
 23    * type=password&gt; form element. [ <a
 24    * href="../../../../../ComponentReference/TextField.html">Component Reference </a>]
 25    * <p>
 26    * As of 4.0, this component can be configurably translated and validated.
 27    *
 28    * @author Howard Lewis Ship
 29    * @author Paul Ferraro
 30    */
 31    public abstract class TextField extends AbstractFormComponent implements TranslatedField
 32    {
 33    public abstract boolean isHidden();
 34   
 35    public abstract Object getValue();
 36    public abstract void setValue(Object value);
 37   
 38    /**
 39    * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 40    */
 41  5 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 42    {
 43  5 String value = getTranslatedFieldSupport().format(this, getValue());
 44   
 45  5 renderDelegatePrefix(writer, cycle);
 46   
 47  5 writer.beginEmpty("input");
 48   
 49  5 writer.attribute("type", isHidden() ? "password" : "text");
 50   
 51  5 writer.attribute("name", getName());
 52   
 53  5 if (isDisabled())
 54  1 writer.attribute("disabled", "disabled");
 55   
 56  5 if (value != null)
 57  5 writer.attribute("value", value);
 58   
 59  5 renderIdAttribute(writer, cycle);
 60   
 61  5 renderDelegateAttributes(writer, cycle);
 62   
 63  5 getTranslatedFieldSupport().renderContributions(this, writer, cycle);
 64  5 getValidatableFieldSupport().renderContributions(this, writer, cycle);
 65   
 66  5 renderInformalParameters(writer, cycle);
 67   
 68  5 writer.closeTag();
 69   
 70  5 renderDelegateSuffix(writer, cycle);
 71    }
 72   
 73    /**
 74    * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 75    */
 76  3 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 77    {
 78  3 String value = cycle.getParameter(getName());
 79   
 80  3 try
 81    {
 82  3 Object object = getTranslatedFieldSupport().parse(this, value);
 83   
 84  2 getValidatableFieldSupport().validate(this, writer, cycle, object);
 85   
 86  1 setValue(object);
 87    }
 88    catch (ValidatorException e)
 89    {
 90  2 getForm().getDelegate().record(e);
 91    }
 92    }
 93   
 94    /**
 95    * Injected.
 96    */
 97    public abstract ValidatableFieldSupport getValidatableFieldSupport();
 98   
 99    /**
 100    * Injected.
 101    */
 102    public abstract TranslatedFieldSupport getTranslatedFieldSupport();
 103   
 104    /**
 105    * @see org.apache.tapestry.form.AbstractFormComponent#isRequired()
 106    */
 107  1 public boolean isRequired()
 108    {
 109  1 return getValidatableFieldSupport().isRequired(this);
 110    }
 111    }