Clover coverage report - Code Coverage for tapestry release 4.0-beta-3
Coverage timestamp: Sun Jul 24 2005 08:26:33 EDT
file stats: LOC: 145   Methods: 6
NCLOC: 70   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractFormComponent.java 100% 100% 100% 100%
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.AbstractComponent;
 18    import org.apache.tapestry.IForm;
 19    import org.apache.tapestry.IMarkupWriter;
 20    import org.apache.tapestry.IRequestCycle;
 21    import org.apache.tapestry.PageRenderSupport;
 22    import org.apache.tapestry.TapestryUtils;
 23    import org.apache.tapestry.valid.IValidationDelegate;
 24    import org.apache.tapestry.valid.ValidationConstants;
 25   
 26    /**
 27    * A base class for building components that correspond to HTML form elements. All such components
 28    * must be wrapped (directly or indirectly) by a {@link Form} component.
 29    *
 30    * @author Howard Lewis Ship
 31    * @author Paul Ferraro
 32    * @since 1.0.3
 33    */
 34    public abstract class AbstractFormComponent extends AbstractComponent implements IFormComponent
 35    {
 36    private static final String SELECTED_ATTRIBUTE_NAME = "org.apache.tapestry.form.SelectedField";
 37   
 38    public abstract IForm getForm();
 39   
 40    public abstract void setForm(IForm form);
 41   
 42    public abstract String getName();
 43   
 44    public abstract void setName(String name);
 45   
 46    /**
 47    * Should be connected to a parameter named "id" (annotations would be helpful here!). For
 48    * components w/o such a parameter, this will simply return null.
 49    */
 50   
 51    public abstract String getIdParameter();
 52   
 53    /**
 54    * Stores the actual id allocated (or null if the component doesn't support this).
 55    */
 56   
 57    public abstract void setClientId(String id);
 58   
 59    /**
 60    * Invoked from {@link #renderFormComponent(IMarkupWriter, IRequestCycle)} (that is, an
 61    * implementation in a subclass), to obtain an id and render an id attribute. Reads
 62    * {@link #getIdParameter()}.
 63    */
 64   
 65  36 protected void renderIdAttribute(IMarkupWriter writer, IRequestCycle cycle)
 66    {
 67    // If the user explicitly sets the id parameter to null, then
 68    // we honor that!
 69   
 70  36 String rawId = getIdParameter();
 71   
 72  36 if (rawId == null)
 73  22 return;
 74   
 75  14 String id = cycle.getUniqueId(rawId);
 76   
 77    // Store for later access by the FieldLabel (or JavaScript).
 78   
 79  14 setClientId(id);
 80   
 81  14 writer.attribute("id", id);
 82    }
 83   
 84    /**
 85    * @see org.apache.tapestry.AbstractComponent#renderComponent(org.apache.tapestry.IMarkupWriter,
 86    * org.apache.tapestry.IRequestCycle)
 87    */
 88  108 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 89    {
 90  108 IForm form = TapestryUtils.getForm(cycle, this);
 91   
 92  107 setForm(form);
 93   
 94  107 if (form.wasPrerendered(writer, this))
 95  5 return;
 96   
 97  102 IValidationDelegate delegate = form.getDelegate();
 98   
 99  102 delegate.setFormComponent(this);
 100   
 101  102 setName(form);
 102   
 103  101 if (form.isRewinding())
 104    {
 105  42 if (!isDisabled())
 106    {
 107  36 rewindFormComponent(writer, cycle);
 108    }
 109    }
 110  59 else if (!cycle.isRewinding())
 111    {
 112  52 if (!isDisabled())
 113  45 delegate.registerForFocus(this, ValidationConstants.NORMAL_FIELD);
 114   
 115  52 renderFormComponent(writer, cycle);
 116   
 117  50 if (delegate.isInError())
 118  1 delegate.registerForFocus(this, ValidationConstants.ERROR_FIELD);
 119    }
 120    }
 121   
 122  22 protected void renderDelegatePrefix(IMarkupWriter writer, IRequestCycle cycle)
 123    {
 124  22 getForm().getDelegate().writePrefix(writer, cycle, this, null);
 125    }
 126   
 127  22 protected void renderDelegateAttributes(IMarkupWriter writer, IRequestCycle cycle)
 128    {
 129  22 getForm().getDelegate().writeAttributes(writer, cycle, this, null);
 130    }
 131   
 132  21 protected void renderDelegateSuffix(IMarkupWriter writer, IRequestCycle cycle)
 133    {
 134  21 getForm().getDelegate().writeSuffix(writer, cycle, this, null);
 135    }
 136   
 137  94 protected void setName(IForm form)
 138    {
 139  94 form.getElementId(this);
 140    }
 141   
 142    protected abstract void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle);
 143   
 144    protected abstract void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle);
 145    }