如何在wicket中手动设置RadioGroup值?

时间:2010-04-20 17:32:36

标签: wicket

我正在尝试在AjaxEventBehavior期间更改Wicket RadioGroup中的所选单选按钮,但无法弄清楚如何执行此操作。特别是当用户在文本框中键入一些文本时,我想将所选的单选按钮更改为我指定的单选按钮。你是怎么做到的?

这是我到目前为止(它在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);

以下是抛出的异常。 java.lang.IllegalArgumentException:无法更新没有的组件 setOutputMarkupId属性设置为true。零件: [MarkupContainer [Component id = myRadioGroup]]

这样做的正确方法是什么?我没有在网上找到大量的wicket文档。

1 个答案:

答案 0 :(得分:5)

为了使用addComponent对myRadioGroup组件进行Ajax刷新,需要添加

myRadioGroup.setOutputMarkupId(true);

以下是一些example code的各种wicket事物和一些documentation