Coverage Report - org.apache.tapestry.form.SelectPropertySelectionRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
SelectPropertySelectionRenderer
0%
0/16
0%
0/4
1.667
 
 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  
 
 20  
 /**
 21  
  * Implementation of {@link IPropertySelectionRenderer} that produces a
 22  
  * <select> element (containing <option> elements).
 23  
  * 
 24  
  * @author Howard Lewis Ship
 25  
  */
 26  
 
 27  0
 public class SelectPropertySelectionRenderer implements IPropertySelectionRenderer
 28  
 {
 29  
 
 30  
     /**
 31  
      * Writes the <select> element. If the {@link PropertySelection} is
 32  
      * {@link PropertySelection#isDisabled() disabled} then a
 33  
      * <code>disabled</code> attribute is written into the tag (though
 34  
      * Navigator 4 will ignore this).
 35  
      */
 36  
 
 37  
     public void beginRender(PropertySelection component, IMarkupWriter writer, IRequestCycle cycle)
 38  
     {
 39  0
         writer.begin("select");
 40  0
         writer.attribute("name", component.getName());
 41  
 
 42  0
         if (component.isDisabled()) 
 43  0
             writer.attribute("disabled", "disabled");
 44  
 
 45  0
         writer.println();
 46  0
     }
 47  
 
 48  
     /**
 49  
      * Closes the &lt;select&gt; element.
 50  
      */
 51  
 
 52  
     public void endRender(PropertySelection component, IMarkupWriter writer,
 53  
             IRequestCycle cycle)
 54  
     {
 55  0
         writer.end(); // <select>
 56  0
     }
 57  
 
 58  
     /**
 59  
      * Writes an &lt;option&gt; element.
 60  
      */
 61  
 
 62  
     public void renderOption(PropertySelection component, IMarkupWriter writer,
 63  
             IRequestCycle cycle, IPropertySelectionModel model, Object option,
 64  
             int index, boolean selected)
 65  
     {
 66  0
         writer.beginEmpty("option");
 67  0
         writer.attribute("value", model.getValue(index));
 68  
 
 69  0
         if (selected) writer.attribute("selected", "selected");
 70  
 
 71  0
         writer.print(model.getLabel(index));
 72  
 
 73  0
         writer.end();
 74  
 
 75  0
         writer.println();
 76  0
     }
 77  
 }