Coverage Report - org.apache.tapestry.contrib.form.checkboxes.ControlledCheckbox
 
Classes in this File Line Coverage Branch Coverage Complexity
ControlledCheckbox
0%
0/19
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.contrib.form.checkboxes;
 16  
 
 17  
 import org.apache.hivemind.ApplicationRuntimeException;
 18  
 import org.apache.tapestry.BaseComponent;
 19  
 import org.apache.tapestry.IForm;
 20  
 import org.apache.tapestry.IMarkupWriter;
 21  
 import org.apache.tapestry.IRequestCycle;
 22  
 import org.apache.tapestry.form.Checkbox;
 23  
 
 24  
 /**
 25  
  * @author mb
 26  
  * @since 4.0
 27  
  */
 28  0
 public abstract class ControlledCheckbox extends BaseComponent
 29  
 {
 30  
 
 31  
     public abstract CheckboxGroup getGroup();
 32  
 
 33  
     public String getCheckboxName()
 34  
     {
 35  0
         Checkbox checkbox = (Checkbox) getComponent("checkbox");
 36  0
         String name = checkbox.getName();
 37  0
         return name;
 38  
     }
 39  
 
 40  
     public IForm getForm()
 41  
     {
 42  0
         Checkbox checkbox = (Checkbox) getComponent("checkbox");
 43  0
         IForm form = checkbox.getForm();
 44  0
         return form;
 45  
     }
 46  
 
 47  
     /**
 48  
      * @see org.apache.tapestry.BaseComponent#renderComponent(org.apache.tapestry.IMarkupWriter,
 49  
      *      org.apache.tapestry.IRequestCycle)
 50  
      */
 51  
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 52  
     {
 53  0
         super.renderComponent(writer, cycle);
 54  
 
 55  0
         registerCheckbox();
 56  0
     }
 57  
 
 58  
     protected void registerCheckbox()
 59  
     {
 60  0
         getCheckboxGroup().registerControlledCheckbox(this);
 61  0
     }
 62  
 
 63  
     public CheckboxGroup getCheckboxGroup()
 64  
     {
 65  0
         CheckboxGroup group = getGroup();
 66  0
         if (group == null)
 67  
         {
 68  0
             IRequestCycle cycle = getPage().getRequestCycle();
 69  0
             group = (CheckboxGroup) cycle
 70  
                     .getAttribute(CheckboxGroup.CHECKBOX_GROUP_ATTRIBUTE);
 71  
         }
 72  0
         if (group == null)
 73  0
             throw new ApplicationRuntimeException(
 74  
                     "The component "
 75  
                             + getExtendedId()
 76  
                             + " must be wrapped by a CheckboxGroup or the 'group' parameter must be set.");
 77  
 
 78  0
         return group;
 79  
     }
 80  
 
 81  
 }