ListView and Serialization

2010-03-26 Thread Michael Gottschalk
Hi,

I have a question concerning the serialization of subcomponents of ListView.

If I understand correctly, then the components that are added to a ListView in 
the populateItem method should be stateless, since they are removed in the 
onPopulate method each time the list view is rendered (as long as reuseItems 
is set to false).

Nevertheless, the subcomponents are saved in the ListView and so they are 
serialized/stored in the session after the page with the ListView has been 
rendered.
This seems unnecessary to me. Why do we have to store components that are 
discarded before the next rendering phase anyway?

So I created a subclass of ListView with the following method overridden:

@Override
protected void onDetach() {
super.onDetach();

if ( !getReuseItems() ) {
removeAll();
}
}

This removes the subcomponents before the page is stored in the session and 
should save some memory in most cases.

Is there a reason why this is not done in ListView itself? Has nobody thought 
about it yet or could there be any problems with this approach?

Cheers,
Michael

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



Re: ListView and Serialization

2010-03-26 Thread Michael Gottschalk
Hi Sven,

you wrote:
 there's no requirement for components inside ListView to be stateless -
 I wonder were you got that from.

I got that from the ListView class comment and from studying the code.
The comment says:

By default, setReuseItems is false, which has the effect that ListView 
replaces all child components by new instances. The idea behind this is that 
you always render the fresh data, and as people usually use ListViews for 
displaying read-only lists [...].

 You can have Links, Buttons or anything else in there so removing all on
 detach is a recipe for disaster for the next incoming request.

I don't think so, because removeAll is already called in ListView.
In onPopulate, which is called in onBeforeRender by AbstractRepeater, the 
following can be found:

if (getReuseItems()) {
[...]
} else {
// Automatically rebuild all ListItems before rendering the
// list view
removeAll();
}

... then the components are recreated using populateItem.

In my opinion, the only difference in my proposal is to call removeAll 
earlier: not in onBeforeRender of the next request cycle, but in onDetach of 
the current request cycle.

Cheers,
Michael

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



Re: ListView and Serialization

2010-03-26 Thread Michael Gottschalk
Hi Sven,

Am Freitag, 26. März 2010 schrieb Sven Meier:
  the only difference in my proposal is to call removeAll earlier:
  not in onBeforeRender of the next request cycle, but in onDetach of
  the current request cycle.
 
 it makes a huge difference:
 If you call removeAll in onDetach, the next request to a component
 inside the ListView will no longer find its receiver:
 
 populateItem(ListItem item) {
   item.add(new Link(link) {
 onClick() {
   // how should this link be clicked when all components are already
 removed??
 }
   });
 }

Yes, you are right, thank you!
I did not think of the possibility that something could happen before 
onBeforeRender is called.

However, for my use case, this is not a problem, since I only use stateless 
components in many of my list views anyway.

I would then create a StatelessListView with my optimization and only use it 
if I know that I have only stateless child components.

Cheers,
Michael

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