Coverage Report - org.apache.tapestry.form.PropertySelection
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertySelection
0%
0/27
0%
0/4
1.5
 
 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  
 import org.apache.tapestry.Tapestry;
 20  
 import org.apache.tapestry.valid.ValidatorException;
 21  
 
 22  
 /**
 23  
  * A component used to render a drop-down list of options that the user may select. [ <a
 24  
  * href="../../../../../components/form/propertyselection.html">Component Reference </a>]
 25  
  * <p>
 26  
  * Earlier versions of PropertySelection (through release 2.2) were more flexible, they included a
 27  
  * <b>renderer </b> property that controlled how the selection was rendered. Ultimately, this proved
 28  
  * of little value and this portion of functionality was deprecated in 2.3 and will be removed in
 29  
  * 2.3.
 30  
  * <p>
 31  
  * Typically, the values available to be selected are defined using an
 32  
  * {@link java.lang.Enum}. A PropertySelection is dependent on an
 33  
  * {@link IPropertySelectionModel} to provide the list of possible values.
 34  
  * <p>
 35  
  * Often, this is used to select a particular {@link java.lang.Enum} to assign to
 36  
  * a property; the {@link org.apache.tapestry.form.EnumPropertySelectionModel} class simplifies this.
 37  
  * <p>
 38  
  * Often, a drop-down list will contain an initial option that serves both as a label and to represent 
 39  
  * that nothing is selected. This can behavior can easily be achieved by decorating an existing 
 40  
  * {@link IPropertySelectionModel} with a {@link LabeledPropertySelectionModel}.
 41  
  * <p>
 42  
  * 
 43  
  */
 44  0
 public abstract class PropertySelection extends AbstractFormComponent implements ValidatableField
 45  
 {   
 46  
     /**
 47  
      * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 48  
      */
 49  
     protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 50  
     {
 51  0
         renderDelegatePrefix(writer, cycle);
 52  
         
 53  0
         writer.begin("select");
 54  0
         writer.attribute("name", getName());
 55  
         
 56  0
         if (isDisabled())
 57  0
             writer.attribute("disabled", "disabled");
 58  
         
 59  0
         renderIdAttribute(writer, cycle);
 60  
         
 61  0
         renderDelegateAttributes(writer, cycle);
 62  
         
 63  0
         getValidatableFieldSupport().renderContributions(this, writer, cycle);
 64  
         
 65  
         // Apply informal attributes.
 66  0
         renderInformalParameters(writer, cycle);
 67  
         
 68  0
         writer.println();
 69  
         
 70  0
         IPropertySelectionModel model = getModel();
 71  
         
 72  0
         if (model == null)
 73  0
             throw Tapestry.createRequiredParameterException(this, "model");
 74  
         
 75  0
         getOptionRenderer().renderOptions(writer, cycle, model, getValue());
 76  
         
 77  0
         writer.end(); // <select>
 78  
 
 79  0
         renderDelegateSuffix(writer, cycle);
 80  0
     }
 81  
 
 82  
     /**
 83  
      * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
 84  
      */
 85  
     protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 86  
     {
 87  0
         String value = cycle.getParameter(getName());
 88  
         
 89  0
         Object object = getModel().translateValue(value);
 90  
         
 91  
         try
 92  
         {
 93  0
             getValidatableFieldSupport().validate(this, writer, cycle, object);
 94  
             
 95  0
             setValue(object);
 96  
         }
 97  0
         catch (ValidatorException e)
 98  
         {
 99  0
             getForm().getDelegate().record(e);
 100  0
         }
 101  0
     }
 102  
     
 103  
     public abstract IPropertySelectionModel getModel();
 104  
     
 105  
     /** @since 2.2 * */
 106  
     public abstract Object getValue();
 107  
 
 108  
     /** @since 2.2 * */
 109  
     public abstract void setValue(Object value);
 110  
     
 111  
     /** Responsible for rendering individual options. */
 112  
     public abstract IOptionRenderer getOptionRenderer();
 113  
     
 114  
     /**
 115  
      * Injected.
 116  
      */
 117  
     public abstract ValidatableFieldSupport getValidatableFieldSupport();
 118  
     
 119  
     /**
 120  
      * @see org.apache.tapestry.form.AbstractFormComponent#isRequired()
 121  
      */
 122  
     public boolean isRequired()
 123  
     {
 124  0
         return getValidatableFieldSupport().isRequired(this);
 125  
     }
 126  
 }