0

Listbox problem with large rows number

asked 2012-02-15 21:08:00 +0800

carpolva gravatar image carpolva
155 4

Hi.

I'm iterating a listbox:

List listaCells;
Listcell lstCell;
Listitem lstItem;
Component componente;

for(Iterator iterator = myListbox.getItems().iterator(); iterator.hasNext();) {
	lstItem = (Listitem) iterator.next(); // each row <listitem>

	if(lstItem != null) {
		listaCells = lstItem.getChildren(); // each column <listcell>
		if(listaCells != null) {			
			for(int j=0; j<listaCells.size(); j++) {
				lstCell = (Listcell) listaCells.get(j);
					if(lstCell!=null){
						componente = lstCell.getFirstChild(); //each component <combobox>, <timebox>...

						if(componente!=null){
							if(componente.getClass().equals(Combobox.class)) {
                                                        ....
                                                        ....

This code works fine with 20 rows.... the problem is after row # 20, at row 21 the "listaCells" variable only has one child (it must be 5 childs for every listCell) and the "componente" variable (lstCell.getFirstChild()) has a NULL value.

When I add rows to the listbox it works fine, but from row 21onwards :'(

.... maybe a bug?, something similar happened to this guy: http://www.zkoss.org/forum/listComment/2986

If you need further information, please let me know.

Thanks :)

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2012-02-17 03:10:47 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

updated 2012-02-17 03:12:12 +0800

This is not a bug. It is to help spliting the initial time to render all listitems. We avoid to render ALL listitems to the full until user really "scroll down" to see them. This way, we can shorten the initial page loading time. If you really need all Listitems to be fully rendered, you can call Listbox#renderAll() to "enforce" rendering all listitems.

http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zul/Listbox.html#renderAll()

Would you tell what use cases you need to iterate the listitems? There might be some other more effective way to do what you really want to achieve.

link publish delete flag offensive edit

answered 2012-02-17 19:54:24 +0800

carpolva gravatar image carpolva
155 4

Hi Henrichen, thanks for your reply.

My use case is the following: There's a screen with a listbox where the users can add or delete rows. This listbox contains comboboxes and timeboxes, if you enter to the following URL you will see a printscreen of my listbox:

http://www.freeimagehosting.net/lr79v

So, the users can select something in each row's combobox and specifiy times in each row's timebox... and finally the user saves the listbox records.

In the window composer class, I'm iterating the listbox just as I showed in this thread's first message. I'm having some problems with the page loading when the listbox has too many rows. The user can paginate the listbox, but can also deactivate the pagination.

What kind of optimization can you suggest me, I'll appreciate any idea.

Thank you very much.

Regards.

link publish delete flag offensive edit

answered 2012-02-20 01:31:42 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

Yes, but then in what situation you need to scan the listitem? For what reason you need to scan the listitem?

link publish delete flag offensive edit

answered 2012-02-20 12:30:05 +0800

carpolva gravatar image carpolva
155 4

The situation is, that I need to get each row's component value (comboboxes' selected values, timeboxes entered values) when the user press a "Save" button.

The same situation applies when the screen is opened or refreshed to load the previous saved records (if exist), for example if the user selected A, B, C, D items in the row's #1 comboboxes and saves these records, next time the user enters to this screen must see A, B, C and D... so, in conclusion I iterate the listbox in order to get/set each component value and sometimes to manipulate their attributes (disable a combo or timebox for example).

Of course, maybe there is a better way to do what I want (specially when there're too many records)... that's why I'm here, I'll appreciate any related help :D

Regards.

link publish delete flag offensive edit

answered 2012-02-21 14:07:36 +0800

irinag gravatar image irinag
45 1

Have the same problem with multiple selection on listbox...

link publish delete flag offensive edit

answered 2012-02-23 02:45:27 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

I would suggest you operate your data via your model but not via your Listitem. The reason is as I have said. To speed up initial load time, we will not render all Listitems . It saves both memory and processing time.

I wonder if you have used ListModel with Listbox? Even better, with ZK6, MVVM will handle all these boilerplate code for you automatically.

http://books.zkoss.org/wiki/Small_Talks/2011/November/MVVM_in_ZK_6_-_Design_CRUD_page_by_MVVM_pattern

link publish delete flag offensive edit

answered 2012-02-26 18:23:30 +0800

carpolva gravatar image carpolva
155 4

updated 2012-02-26 18:23:54 +0800

Thanks henrichen, now I'm operating via model... and I'm gonna read about ZK 6 new features.

Regards.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-02-15 21:08:00 +0800

Seen: 402 times

Last updated: Feb 26 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More