开发者

How do you manually set a RadioGroup value in wicket?

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").setDefaultModel开发者_如何学CObject("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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜