Coverage Report - org.apache.tapestry.valid.FieldLabel
 
Classes in this File Line Coverage Branch Coverage Complexity
FieldLabel
0%
0/30
0%
0/20
3.6
 
 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.valid;
 16  
 
 17  
 import org.apache.tapestry.*;
 18  
 import org.apache.tapestry.form.IFormComponent;
 19  
 
 20  
 /**
 21  
  * Used to label an {@link IFormComponent}. Because such fields know their
 22  
  * displayName (user-presentable name), there's no reason to hard code the label
 23  
  * in a page's HTML template (this also helps with localization). [ <a
 24  
  * href="../../../../../components/form/fieldlabel.html">Component Reference
 25  
  * </a>]
 26  
  * 
 27  
  * @author Howard Lewis Lewis Ship
 28  
  */
 29  
 
 30  0
 public abstract class FieldLabel extends AbstractComponent
 31  
 {
 32  
 
 33  
     // Parameter
 34  
     public abstract boolean isPrerender();
 35  
 
 36  
     /**
 37  
      * Gets the {@link IForm}&nbsp;and {@link IValidationDelegate delegate},
 38  
      * then renders the label obtained from the field. Does nothing when
 39  
      * rewinding.
 40  
      */
 41  
 
 42  
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 43  
     {
 44  0
         IForm form = TapestryUtils.getForm(cycle, this);
 45  
         
 46  0
         IFormComponent field = getField();
 47  
         
 48  0
         if (field != null && isPrerender())
 49  0
             form.prerenderField(writer, field, getLocation());
 50  
         
 51  0
         if (cycle.isRewinding()) 
 52  0
             return;
 53  
         
 54  0
         String displayName = getDisplayName();
 55  
         
 56  0
         if (displayName == null)
 57  
         {
 58  0
             if (field == null)
 59  0
                 throw Tapestry.createRequiredParameterException(this, "field");
 60  
             
 61  0
             displayName = field.getDisplayName();
 62  
             
 63  0
             if (displayName == null)
 64  0
                 throw new BindingException(ValidMessages.noDisplayName(this,field), this, null, getBinding("field"), null);
 65  
         }
 66  
         
 67  0
         IValidationDelegate delegate = form.getDelegate();
 68  
         
 69  0
         String id = (field == null) ? null : field.getClientId();
 70  
         
 71  0
         if (field != null)
 72  0
             delegate.writeLabelPrefix(field, writer, cycle);
 73  
         
 74  0
         writer.begin("label");
 75  
 
 76  0
         renderInformalParameters(writer, cycle);
 77  
 
 78  0
         if (id != null) 
 79  0
             writer.attribute("for", id);
 80  
                 
 81  0
         delegate.writeLabelAttributes(writer, cycle, field);
 82  
         
 83  0
         delegate.beforeLabelText(writer, cycle, field);
 84  
         
 85  0
         writer.print(displayName, getRaw());
 86  
         
 87  0
         delegate.afterLabelText(writer, cycle, field);
 88  
         
 89  0
         writer.end();
 90  
         
 91  0
         if (field != null)
 92  0
             delegate.writeLabelSuffix(field, writer, cycle);
 93  0
     }
 94  
 
 95  
     /** displayName parameter. */
 96  
     public abstract String getDisplayName();
 97  
 
 98  
     /** field parameter. */
 99  
     public abstract IFormComponent getField();
 100  
 
 101  
     /** raw parameter. */
 102  
     public abstract boolean getRaw();
 103  
 }