tags:

views:

358

answers:

1

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.

+3  A: 

In order to use addComponent to have an Ajax refresh of your myRadioGroup component, you need to add

myRadioGroup.setOutputMarkupId(true);

Here's some example code of assorted wicket things and some documentation.

Don Roby