Ok, attachments don't work.  Code follows inline. 

++++++++++++++++++
package tapestry.components;

import org.apache.tapestry.form.RadioGroup;
import org.apache.tapestry.form.AbstractFormComponent;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.annotations.Parameter;
import org.apache.tapestry.annotations.ComponentClass;
import org.apache.hivemind.ApplicationRuntimeException;

/**
 * TODO: Doc this.
 *
 * @author Ben Sommerville
 */
@ComponentClass(allowBody = false, reservedParameters = "checked,type,name")
public abstract class FormRadio extends AbstractFormComponent  {


    @Parameter(name="id", defaultValue="id")
    public abstract String getIdParameter();

    @Parameter
    public abstract String getDisplayName();

    @Parameter
    public abstract boolean isDisabled();

    @Parameter
    public abstract Object getValue();

    /**
     *  Renders the form element, or responds when the form containing the
element
     *  is submitted (by checking [EMAIL PROTECTED]
org.apache.tapestry.form.Form#isRewinding()}.
     *
     *
     **/

    protected void renderFormComponent(IMarkupWriter writer, IRequestCycle
cycle)
    {

        RadioGroup group = RadioGroup.get(cycle);
        if (group == null)
            throw new ApplicationRuntimeException(
                Tapestry.getMessage("Radio.must-be-contained-by-group"),
                this,
                null,
                null);

        // The group determines rewinding from the form.
//
//        boolean rewinding = group.isRewinding();

        int option = group.getNextOptionId();
//
//        if (rewinding)
//        {
//            // 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());
//            return;
//        }
//
        writer.beginEmpty("input");

        writer.attribute("type", "radio");

        writer.attribute("name", group.getName());

        renderIdAttribute(writer, cycle);

        // 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);

        renderInformalParameters(writer, cycle);

    }


    protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle
cycle) {
        RadioGroup group = RadioGroup.get(cycle);
        if (group == null)
            throw new ApplicationRuntimeException(
                Tapestry.getMessage("Radio.must-be-contained-by-group"),
                this,
                null,
                null);

        // The group determines rewinding from the form.


        int option = group.getNextOptionId();

        // 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());
    }

}

-----Original Message-----
From: Ben Sommerville [mailto:[EMAIL PROTECTED] 
Sent: Thursday, 26 October 2006 9:33 PM
To: 'Tapestry users'
Subject: RE: Dynamic Radiogroup

I ran into this problem too.  FieldLabel does not work with Radio because it
is not an IFormComponent.

The order of FieldLabel & the component it refers to doesn't matter.  Except
that if you put the FieldLabel after the component you have to set
prerender=false.

I worked around this by creating a radio component that is a form component.
The
attached file has the class.  Now the disclaimer- this is code from 6 or 7
months ago on a project that didn't finish & was developerd early in my
tapestry learning cycle - treat with appropriate caution :)

cheers,
Ben
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to