Hi all,
I have some problem with ListViews and AjaxFallbackButton:
The main idea is, that I have a Listview and a NewEntry button outside
the LV. If I press the new button I'm gonna have a new ddc and Textfield
and a Remove button in the LV. So far it works as intended, until I'm
trying to remove an entry from the list. First I tought the problem is
around ArrayList#remove because it always remove the first occurrence of
the object. That's why I created an UUID field with random id for every
single listelement, and I also overrided the eguals function, so it
would handle the uuid's.
But, this is still not working, I checked the lists elements, and from
the ArrayList the correct one is deleted, but on the page a wrong one
makes dissappear, making the remove buttons worthless (because the
removable item is already removed...)
I tried this code:
public HomePage(final PageParameters pageParameters) {
final Person person = new Person();
final Form form = new Form("form") {
@Override
protected void onSubmit() {
super.onSubmit();
}
};
final WebMarkupContainer rowPanel = new
WebMarkupContainer("rowPanel");
final ListView<IMAccount> listview = new
ListView<IMAccount>("ims", new PropertyModel(person, "ImAccounts")) {
@Override
protected void populateItem(ListItem<IMAccount> item) {
final IMAccount acc = item.getModelObject();
item.add(new DropDownChoice("imProtocol",
new PropertyModel(acc, "protocol"),
Arrays.asList(IMAccount.IMProtocol.values())));
item.add(new TextField("imPresenceID",
new PropertyModel(acc, "presenceID")));
item.add(new AjaxFallbackButton("imRemove", form) {
@Override
public void onSubmit(AjaxRequestTarget target,
Form<?> form) {
System.out.println("before removing the item:");
for (IMAccount iMAccount :
person.getImAccounts()) {
System.out.println(iMAccount.getUuid());
}
System.out.println("this should be removed: " +
acc.getUuid());
person.getImAccounts().remove(acc);
System.out.println("after removing:");
for (IMAccount iMAccount :
person.getImAccounts()) {
System.out.println(iMAccount.getUuid());
}
if (target != null) {
target.addComponent(rowPanel);
}
}
}.setDefaultFormProcessing(false));
}
};
listview.setReuseItems(true);
rowPanel.add(listview);
rowPanel.add(new AjaxFallbackButton("imAdd", form) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?>
form) {
final List<IMAccount> list = listview.getModelObject();
list.add(new IMAccount(IMAccount.IMProtocol.icq, ""));
if (target != null) {
target.addComponent(rowPanel);
}
}
}.setDefaultFormProcessing(false));
rowPanel.setOutputMarkupId(true);
form.add(rowPanel);
add(form);
}
What am I doing wrong? I have created a quickstart for the problem,
which is available here:
http://users.hszk.bme.hu/~mp695/myproject.zip
Should I create a JIRA issue, or did I made some terrible mistake? :)
Thanks for any help
Best Regards,
Peter Major
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]