How do you manually set a RadioGroup value in wicket?

Posted by Kane on Stack Overflow See other posts from Stack Overflow or by Kane
Published on 2010-04-20T17:32:35Z Indexed on 2010/04/20 17:33 UTC
Read the original article Hit count: 299

Filed under:

I'm trying to change the selected radio button in a Wicket RadioGroup during an AjaxEventBehavior but can't figure out how to do so. Specifically when a user types some text in a textbox I want to change the selected radio button to one I specify. How do you do this?

Here's what I have so far (it crashes on addComponent):

myRadioGroup = new RadioGroup("MyNewGroup", new PropertyModel(getPojo(), "selectedGroup"));
Radio internalRadio = new Radio("InternalDirectoryNumber", new Model("Internal"));
myRadioGroup .add(internalRadio);
Radio externalRadio = new Radio("OtherMobileNumber", new Model("External"));
myRadioGroup .add(externalRadio);
TextField myTxtField= new TextField("TextBoxPrivateNumber", new PropertyModel(getVoiceItem(), "privateMobilePhone"));

myTxtField.add( new AjaxEventBehavior( "onKeyUp" )
{
 @Override
 protected void onEvent(AjaxRequestTarget target) 
 {
  Component component = target.getPage().get("myForm:MyNewGroup").setDefaultModelObject("External");
  target.addComponent(component); //this causes an exception

 }
});
myRadioGroup .add(myTxtField);

Here is the exception that's thrown. java.lang.IllegalArgumentException: cannot update component that does not have setOutputMarkupId property set to true. Component: [MarkupContainer [Component id = myRadioGroup]]

What's the proper way to do this? I'm not finding a whole lot of wicket documentation for this online.

© Stack Overflow or respective owner

Related posts about wicket