[英]Wicket: Update Model on DropDownChoice Item Selection Event
選擇DropDownChoice項目后,我需要立即更新模型或對象。
貝婁是我正在工作的代碼:
add(new ListView[Company]("listCompanies", listData) {
override protected def onBeforeRender() {
//
// ...
super.onBeforeRender()
}
def populateItem(item: ListItem[Company]) = {
var company = item.getModelObject()
//...
val listClients: java.util.List[Client] = clientControler.listClients
item.add(new DropDownChoice("clientSelection", listClients,new ChoiceRenderer[Client]("name")))
在具有“公司對象”屬性的列表視圖中,選擇“ DropDownChoice”的名稱屬性后,將使用選定的“客戶名稱”來更新模型“公司”。
我該如何實現?
謝謝
我認為您可以覆蓋onSelectionChanged。 但是,您還需要重寫wantOnSelectionChangedNotifications以返回true才能使其工作。 這樣的事情。
DropDownChoice<Client> dropDownChoice = new DropDownChoice("clientSelection", listClients) {
@Override
protected boolean wantOnSelectionChangedNotifications() {
return true;
}
@Override
protected void onSelectionChanged(Object newSelection) {
// Do something here when selection is changed
}
};
您需要添加更新行為:
add(new DropDownChoice<Client>("clientSelection", listClients)
.add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
// update your model here
// then you need to add model to target
target.add();
}
}));
我認為您可以在DropDownChoice上使用AjaxEventBehavior:
item.add(new DropDownChoice("clientSelection", listClients,new ChoiceRenderer[Client("name")).add(new AjaxEventBehavior("change") {
@Override
protected void onEvent(AjaxRequestTarget target) {
// TODO Auto-generated method stub
}
}))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.