You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by petivagyoken <pe...@gmail.com> on 2015/10/01 22:55:40 UTC

Wicket ListView ajax removes always removes last element in list

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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket ListView ajax removes always removes last element in list

Posted by Sven Meier <sv...@meiers.net>.
Show us the code.

Sven

On 01.10.2015 23:42, petivagyoken wrote:
> createComponent is an abstract method that creates a simple Panel with input
> fields, it has no markupid set or anything. Maybe that is the issue?
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-ListView-ajax-removes-always-removes-last-element-in-list-tp4672088p4672090.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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


Re: Wicket ListView ajax removes always removes last element in list

Posted by petivagyoken <pe...@gmail.com>.
createComponent is an abstract method that creates a simple Panel with input
fields, it has no markupid set or anything. Maybe that is the issue?

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

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


Re: Wicket ListView ajax removes always removes last element in list

Posted by Sven Meier <sv...@meiers.net>.
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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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