Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 119   Methods: 2
NCLOC: 43   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
AbstractTextField.java 92.9% 95.7% 100% 94.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.IForm;
 18   
 import org.apache.tapestry.IMarkupWriter;
 19   
 import org.apache.tapestry.IRequestCycle;
 20   
 
 21   
 /**
 22   
  * Base class for implementing various types of text input fields. This includes {@link TextField}
 23   
  * and {@link org.apache.tapestry.valid.ValidField}.
 24   
  * 
 25   
  * @author Howard Lewis Ship
 26   
  * @since 1.0.2
 27   
  */
 28   
 
 29   
 public abstract class AbstractTextField extends AbstractFormComponent
 30   
 {
 31   
     /**
 32   
      * Renders the form element, or responds when the form containing the element is submitted (by
 33   
      * checking {@link Form#isRewinding()}.
 34   
      */
 35   
 
 36  24
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 37   
     {
 38  24
         IForm form = getForm(cycle);
 39   
 
 40  24
         if (form.wasPrerendered(writer, this))
 41  0
             return;
 42   
 
 43   
         // It isn't enough to know whether the cycle in general is rewinding, need to know
 44   
         // specifically if the form which contains this component is rewinding.
 45   
 
 46  24
         boolean rewinding = form.isRewinding();
 47   
 
 48   
         // If the cycle is rewinding, but the form containing this field is not,
 49   
         // then there's no point in doing more work.
 50   
 
 51  24
         if (!rewinding && cycle.isRewinding())
 52  3
             return;
 53   
 
 54   
         // Used whether rewinding or not.
 55   
 
 56  21
         String name = form.getElementId(this);
 57   
 
 58  21
         if (rewinding)
 59   
         {
 60  8
             if (!isDisabled())
 61   
             {
 62  7
                 String value = cycle.getParameter(name);
 63   
 
 64  7
                 updateValue(value);
 65   
             }
 66   
 
 67  8
             return;
 68   
         }
 69   
 
 70  13
         writer.beginEmpty("input");
 71   
 
 72  13
         writer.attribute("type", isHidden() ? "password" : "text");
 73   
 
 74  13
         if (isDisabled())
 75  2
             writer.attribute("disabled", "disabled");
 76   
 
 77  13
         writer.attribute("name", name);
 78   
 
 79  13
         String value = readValue();
 80  13
         if (value != null)
 81  11
             writer.attribute("value", value);
 82   
 
 83  13
         renderInformalParameters(writer, cycle);
 84   
 
 85  13
         beforeCloseTag(writer, cycle);
 86   
 
 87  12
         writer.closeTag();
 88   
     }
 89   
 
 90   
     /**
 91   
      * Invoked from {@link #render(IMarkupWriter, IRequestCycle)}just before the tag is closed.
 92   
      * This implementation does nothing, subclasses may override.
 93   
      */
 94   
 
 95  6
     protected void beforeCloseTag(IMarkupWriter writer, IRequestCycle cycle)
 96   
     {
 97   
         // Do nothing.
 98   
     }
 99   
 
 100   
     /**
 101   
      * Invoked by {@link #render(IMarkupWriter writer, IRequestCycle cycle)}when a value is
 102   
      * obtained from the {@link javax.servlet.http.HttpServletRequest}.
 103   
      */
 104   
 
 105   
     abstract protected void updateValue(String value);
 106   
 
 107   
     /**
 108   
      * Invoked by {@link #render(IMarkupWriter writer, IRequestCycle cycle)}when rendering a
 109   
      * response.
 110   
      * 
 111   
      * @return the current value for the field, as a String, or null.
 112   
      */
 113   
 
 114   
     abstract protected String readValue();
 115   
 
 116   
     public abstract boolean isHidden();
 117   
 
 118   
     public abstract boolean isDisabled();
 119   
 }