Reputation: 1282
I need to update a model or object immediately after select a DropDownChoice item.
Bellow is the code that I'm working:
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")))
In the Listview with properties of Company Object, after choose a name property of the DropDownChoice, the model Company would be updated with the Client Name selected.
How can I achieve this?
Thanks
Upvotes: 0
Views: 8378
Reputation: 1
I think you can use an AjaxEventBehavior on your DropDownChoice:
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
}
}))
Upvotes: 0
Reputation: 16555
you need to add updating behavior:
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();
}
}));
Upvotes: 7
Reputation: 12617
I think you can override onSelectionChanged. But you also need to override wantOnSelectionChangedNotifications to return true to make it work. Something like this.
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
}
};
Upvotes: 7