Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2004, 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
 package org.apache.tapestry.form;
 
 import  org.apache.hivemind.ApplicationRuntimeException;
Implements a component that manages an HTML <input type=radio> form element. Such a component must be wrapped (possibly indirectly) inside a RadioGroup component. [Component Reference]

Radio and RadioGroup are generally not used (except for very special cases). Instead, a PropertySelection component is used.

Author(s):
Howard Lewis Ship
 
 
 public abstract class Radio extends AbstractFormComponent
 {
    
Renders the form element, or responds when the form containing the element is submitted (by checking Form.isRewinding().
 
 
     protected void renderFormComponent(IMarkupWriter writerIRequestCycle cycle)
     {
         RadioGroup group = RadioGroup.get(cycle);
 
         if (group == null)
             throw new ApplicationRuntimeException(Tapestry.getMessage("Radio.must-be-contained-by-group"),
                                                   this,
                                                   null,
                                                   null);
 
         int option = group.getNextOptionId();
 
         setClientId(group.getName()+option);
         setName(group.getName());
 
         writer.beginEmpty("input");
 
         writer.attribute("type""radio");
 
         writer.attribute("name"getName());
 
         renderIdAttribute(writercycle);
 
         // As the group if the value for this Radio matches the selection
         // for the group as a whole; if so this is the default radio and is checked.
 
         if (group.isSelection(getValue()))
             writer.attribute("checked""checked");
 
         if (isDisabled() || group.isDisabled())
             writer.attribute("disabled""disabled");
 
         // The value for the Radio matches the option number (provided by the RadioGroup).
         // When the form is submitted, the RadioGroup will know which option was,
         // in fact, selected by the user.
 
         writer.attribute("value"option);
 
         // don't make it a reserved parameter to preserve backwards compatibility
         if ( !isParameterBound("onclick") )
         {
             String onclickCall = "tapestry.byId('"+group.getClientId()+"').onChange("+option+");";
             writer.attribute("onclick"onclickCall);
         }
 
         renderInformalParameters(writercycle);
 
         writer.closeTag();
     }
 
     protected void rewindFormComponent(IMarkupWriter writerIRequestCycle cycle)
     {
        RadioGroup group = RadioGroup.get(cycle);
        if (group == null)
            throw new ApplicationRuntimeException(
                    Tapestry.getMessage("Radio.must-be-contained-by-group"),
                    this,
                    null,
                    null);
        int option = group.getNextOptionId();
        setClientId(group.getName()+option);
        setName(group.getName());
        // If not disabled and this is the selected button within the radio group,
        // then update set the selection from the group to the value for this
        // radio button.  This will update the selected parameter of the RadioGroup.
        if (!isDisabled() && !group.isDisabled() && group.isSelected(option))
            group.updateSelection(getValue());
    }

    
Overridden to do nothing so that special RadioGroup semantics are handled properly.

Parameters:
form The form to set the name on.
    protected void setName(IForm form)
    {
    }
    public abstract boolean isDisabled();
    public abstract Object getValue();
New to GrepCode? Check out our FAQ X