如何在 wicket 中手动设置 RadioGroup 值?
我试图在 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]]
执行此操作的正确方法是什么?我没有在网上找到大量相关的检票口文档。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了使用 addComponent 对 myRadioGroup 组件进行 Ajax 刷新,您需要添加
以下内容 示例各种 wicket 内容的代码和一些文档。
In order to use addComponent to have an Ajax refresh of your myRadioGroup component, you need to add
Here's some example code of assorted wicket things and some documentation.