2013-10-08 78 views
3

如何在導葉中獲得單選按鈕「活」?我的意思是如果我有一個帶有兩個選項A和B的單選按鈕,並且我想向按鈕添加一個ajax行爲(在更改,更新,任何作品上),以便如果我選擇A,它會發生頁面中的某些事情,如果我選擇B發生其他事情。你可以幫我嗎?執行onUpdate在Ajax行爲中獲取單選按鈕選擇值

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的型號都已經被更新:

回答

10

只需添加一個AjaxFormChoiceComponentUpdatingBehaviorRadioChoice。請記住添加到target所有要通過AJAX刷新的組件(當然也可以爲它們設置setOutputMarkupId(true))。

這裏有一個在線示例,其中包含了您要查找的源代碼here。相關的源代碼文件是this one