【问题标题】:Get radio button choice value in Ajax Behavior获取 Ajax 行为中的单选按钮选择值
【发布时间】:2013-10-15 07:49:08
【问题描述】:

如何在检票口中“实时”选择单选按钮?我的意思是,如果我有一个带有两个选项 A 和 B 的单选按钮,并且我想向该按钮添加一个 ajax 行为(更改时、更新时,无论工作如何),这样如果我选择 A,它会在页面中发生某些事情,如果我选择了 B 发生了其他事情。你能帮助我吗?

【问题讨论】:

    标签: java radio-button wicket


    【解决方案1】:

    只需将AjaxFormChoiceComponentUpdatingBehavior 添加到RadioChoice

    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);
    

    RadioChoice 的模型在执行onUpdate 时已经更新。请记住将所有要通过 AJAX 刷新的组件添加到 target(当然还要为它们设置 setOutputMarkupId(true))。

    有一个在线示例,其中包含您正在寻找的源代码here。相关源代码文件为this one

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-28
      • 2012-07-18
      • 2015-03-28
      • 2012-12-15
      • 2021-12-31
      • 2011-08-16
      • 1970-01-01
      相关资源
      最近更新 更多