如何在检票口中“实时”选择单选按钮?我的意思是,如果我有一个带有两个选项A和B的单选按钮,我想在按钮上添加一个ajax行为(在更改时,在更新时,无论有什么用),这样如果我选择A它会在页面中发生某些事情,如果我选择B发生了别的事情.你能帮助我吗?
解决方法:
RadioChoice radioChoice = new RadioChoice("myRadio", choiceList);
radioChoice.add( new AjaxFormChoiceComponentUpdatingBehavior("onchange") {
protected void onUpdate(AjaxRequestTarget target) {
// Ajax actions here
System.out.println("The selected value is " + getComponent().getDefaultModelObjectAsString()));
}
} );
form.add(radioChoice);
执行onUpdate时,RadioChoice的模型已经更新.请记住添加目标所有要通过AJAX刷新的组件(当然还要将setOutputMarkupId(true)设置为它们).
这是一个在线示例,其中包含您正在寻找的源代码here.相关的源代码文件是this one.
标签:java,radio-button,wicket
来源: https://codeday.me/bug/20190718/1492155.html