I have a similar issue, but I don't know which radio should be checked until
runtime.  So I can't hard-code it in the HTML; I have to determine it from
my DAO in the radiogroup's parent panel constructor.  I'm using the model to
determine which radio to select, and it works fine once you click, but my
problem is that nothing is selected when the page first loads.  Here is the
code:

    // This sets up the radiobuttons
    private enum eContentTypeControl { TEXTFIELD, DROPDOWN };
    private class ContentTypeControlBean implements Serializable
    {
        private static final long serialVersionUID = 1L;
        private eContentTypeControl m_control = null;
        
        public ContentTypeControlBean( eContentTypeControl control )
        {
            m_control = control;
        }
        
        public eContentTypeControl getControl()
        {
            return m_control;
        }
        
        public void setControl( eContentTypeControl control )
        {
            m_control = control;
        }
    }
....
        // Figure out which radiobutton should be selected
        List<String> mimeTypeList = model.getCommonMimeTypes();
        eContentTypeControl contentTypeControl = null;
        if ( mimeTypeList.contains(
model.getCachedDefaults().getContentType() ) )
        {
            contentTypeControl = eContentTypeControl.DROPDOWN;
        }
        else
        {
            contentTypeControl = eContentTypeControl.TEXTFIELD;
        }
                        
        // Create the radiogroup with the right 
        m_ContentTypeRadioGroupBean = new ContentTypeControlBean(
contentTypeControl );
        RadioGroup<ContentTypeControlBean> contentTypeRadioGroup = 
            new RadioGroup<ContentTypeControlBean>( 
                    "contentTypeRadioGroup", 
                    new PropertyModel<ContentTypeControlBean>(
m_ContentTypeRadioGroupBean, "control" ) );
...        
        m_rbUseTextFieldContentType = 
            new Radio<ContentTypeControlBean>( 
                    "textfieldContentType", 
                    new Model<ContentTypeControlBean>( new
ContentTypeControlBean( eContentTypeControl.TEXTFIELD ) ),
                    contentTypeRadioGroup );
        contentTypeRadioGroup.add( m_rbUseTextFieldContentType );

        m_rbUseDropDownContentType = 
            new Radio<ContentTypeControlBean>( 
                    "dropdownContentType", 
                    new Model<ContentTypeControlBean>( new
ContentTypeControlBean( eContentTypeControl.DROPDOWN ) ),
                    contentTypeRadioGroup );
        contentTypeRadioGroup.add( m_rbUseDropDownContentType );

and here is the HTML:

                     <input wicket:id="textfieldContentType"
type="radio"></input>
<!--                     <input wicket:id="dropdownContentType" type="radio"
checked="true"></input> -->
                     <input wicket:id="dropdownContentType"
type="radio"></input>

The dropdown radio is checked when the page loads if I have "checked =
'true'" in the HTML but since I don't know whether it should be checked at
compile time, I can't do that.  I tried using an AttributeModifier in the
parent panel's constructor but it has no effect:

        if ( contentTypeControl == eContentTypeControl.TEXTFIELD )
        {
            m_rbUseTextFieldContentType.add( new AttributeModifier(
"checked", new Model( "true" ) ) );
            m_rbUseDropDownContentType.add( new AttributeModifier(
"checked", new Model( "false" ) ) );
        }
        else
        {
            m_rbUseTextFieldContentType.add( new AttributeModifier(
"checked", new Model( "false" ) ) );
            m_rbUseDropDownContentType.add( new AttributeModifier(
"checked", new Model( "true" ) ) );
        }

Any ideas?

-- 
View this message in context: 
http://www.nabble.com/radio-and-radiogroup-default-%22checked%22-not-working--tp22248204p25294447.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to