Hi,

please show us #createComponent().

It seems to me that the item is correctly removed from the list, but your components still cling to the former item under their index.

Have fun
Sven


On 01.10.2015 22:55, petivagyoken wrote:
Hi I posted this question on Stackoverflow, I'd like to do the same here as
well now:

I have a way to add panels in a listview. Each panel is associated with an
Object of type Type. I have an 'add' and an some 'remove' AjaxSubmitLinks.
Both have setDefaultFormProcessing(false) because I want non-submitted /
validated values to remain when someone add or removes an element.
setReuseItems(true) is set for the ListView. Please see the code snippet
below.

          ListView itemContainer = new ListView<Type>("list", getList()) {
             @Override
             protected void populateItem(final ListItem<Type> listItem) {
                 final Component element =
createComponent(listItem.getModel());
                 listItem.add(element);
                 listItem.add(new AjaxSubmitLink("remove") {

                     @Override
                     protected void onSubmit(AjaxRequestTarget target,
Form<?> form) {
                         getList().remove(listItem.getIndex());
                         target.add(wrapper);
                     }
                 }.setDefaultFormProcessing(false));
             }
         };
         itemContainer.setReuseItems(true);
         add(itemContainer);
         add(new AjaxSubmitLink("add") {
             @Override
             protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
                 Type object = addObject();
                 getList().add(object);
                 target.add(wrapper);
             }

             @Override
             public boolean isVisible() {
                 return getList().size() < DSAddableField.this.max &&
isEditable();
             }
         }.setDefaultFormProcessing(false));


Where wrapper contains everything, so everything is reloaded with Ajax. All
works well, expcet no matter which remove link I click the last element is
being removed. equals() method is overriden on Type based on a UUID check. I
did a debug and it would seem to me that the right element is removed from
the ListModel, but wrong values are sent down by the ajax response.

How can I get this to work? I tried to remove setReuseItem(true), but than
the non-saved values for list items were not reloaded. (Panels contain lot
of input fields)

Any suggestions?

UPDATE:

I already tried to remove the object with
getList().remove(listItem.getModelObject()), this was second solution but
still failed.

Regardless if I use remove by index or by modelobject the right element is
being removed from the list when using debugger.

UDAPTE 2:

If I remove "final int index = listItem.getIndex();" the right element is
removed opposed to the last one but when I add a new one to the list non
saved inputs are cleared which is the original problem I'm trying to solve.
Please advise.

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Wicket-ListView-ajax-removes-always-removes-last-element-in-list-tp4672088.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to