Clover coverage report - Code Coverage for tapestry release 4.0-beta-10
Coverage timestamp: Sat Oct 8 2005 19:08:05 EDT
file stats: LOC: 94   Methods: 3
NCLOC: 39   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Checkbox.java 100% 93.8% 66.7% 91.3%
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 &lt;input type=checkbox&gt; form element. [ <a
 23    * href="../../../../../ComponentReference/Checkbox.html">Component Reference </a>]
 24    * <p>
 25    * As of 4.0, this component can be validated.
 26    *
 27    * @author Howard Lewis Ship
 28    * @author Paul Ferraro
 29    */
 30    public abstract class Checkbox extends AbstractFormComponent implements ValidatableField
 31    {
 32    /**
 33    * @see org.apache.tapestry.form.validator.AbstractRequirableField#renderRequirableFormComponent(org.apache.tapestry.IMarkupWriter,
 34    * org.apache.tapestry.IRequestCycle)
 35    */
 36  4 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 37    {
 38  4 writer.beginEmpty("input");
 39  4 writer.attribute("type", "checkbox");
 40   
 41  4 writer.attribute("name", getName());
 42   
 43  4 if (isDisabled())
 44  1 writer.attribute("disabled", "disabled");
 45   
 46  4 if (getValue())
 47  3 writer.attribute("checked", "checked");
 48   
 49  4 renderIdAttribute(writer, cycle);
 50   
 51  4 renderInformalParameters(writer, cycle);
 52   
 53  4 writer.closeTag();
 54    }
 55   
 56    /**
 57    * In traditional HTML, many checkboxes would have the same name but different values. Under
 58    * Tapestry, it makes more sense to have different names and a fixed value. For a checkbox, we
 59    * only care about whether the name appears as a request parameter.
 60    */
 61  3 protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 62    {
 63  3 String value = cycle.getParameter(getName());
 64   
 65  3 try
 66    {
 67    // This is atypical validation - since this component does not explicitly bind to an object
 68  3 getValidatableFieldSupport().validate(this, writer, cycle, value);
 69   
 70  2 setValue(value != null);
 71    }
 72    catch (ValidatorException e)
 73    {
 74  1 getForm().getDelegate().record(e);
 75    }
 76    }
 77   
 78    public abstract boolean getValue();
 79   
 80    public abstract void setValue(boolean selected);
 81   
 82    /**
 83    * Injected.
 84    */
 85    public abstract ValidatableFieldSupport getValidatableFieldSupport();
 86   
 87    /**
 88    * @see org.apache.tapestry.form.AbstractFormComponent#isRequired()
 89    */
 90  0 public boolean isRequired()
 91    {
 92  0 return getValidatableFieldSupport().isRequired(this);
 93    }
 94    }