You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by markus138138 <ma...@gmail.com> on 2014/06/21 14:35:18 UTC

Replacing items in a ListView

I want to change the data of a listview on a Button Click.

This is what I do currently:

/
final PageableListView<Users> listview = new PageableListView<Users>("rows",
displayList, 10) {
    //.... 
    protected void populateItem(final ListItem<Users> item) {
	item.add(new Label("username").setOutputMarkupId(true));
        // .. other fields
    }
}/
/
final IndicatingAjaxFallbackLink<MyPanel> sublist = new
IndicatingAjaxFallbackLink<MyPanel>("sublist") {
	public void onClick(AjaxRequestTarget target) {
		displayList = // get new list
		listview.setList(displayList);
	        target.addChildren(listview, Label.class);
	}
};
add(sublist);/


This works if the new list is exactly the same size ad the old list. In any
other case I get an


/Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1/

How can I fix this problem?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Replacing-items-in-a-ListView-tp4666326.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: Replacing items in a ListView

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

There is a limitation in Wicket that requires you to repaint the whole
repeater in Ajax requests.
Actually you should repaint the parent of the repeater!

You can repaint just some children components as you do but as you see
there are "issues".
By default ListViews remove all their children (ListItems) after render. So
in the next request during the action phase (onClick) the ListView has no
children at all.
See ListView#setReuseItems(boolean) javadoc.

What is the stacktrace of the exception ?

Martin Grigorov
Wicket Training and Consulting


On Sat, Jun 21, 2014 at 3:35 PM, markus138138 <ma...@gmail.com> wrote:

> I want to change the data of a listview on a Button Click.
>
> This is what I do currently:
>
> /
> final PageableListView<Users> listview = new
> PageableListView<Users>("rows",
> displayList, 10) {
>     //....
>     protected void populateItem(final ListItem<Users> item) {
>         item.add(new Label("username").setOutputMarkupId(true));
>         // .. other fields
>     }
> }/
> /
> final IndicatingAjaxFallbackLink<MyPanel> sublist = new
> IndicatingAjaxFallbackLink<MyPanel>("sublist") {
>         public void onClick(AjaxRequestTarget target) {
>                 displayList = // get new list
>                 listview.setList(displayList);
>                 target.addChildren(listview, Label.class);
>         }
> };
> add(sublist);/
>
>
> This works if the new list is exactly the same size ad the old list. In any
> other case I get an
>
>
> /Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1/
>
> How can I fix this problem?
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Replacing-items-in-a-ListView-tp4666326.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
>
>