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