-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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 :)
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.
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.
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.
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
Thanks henrichen, now I'm operating via model... and I'm gonna read about ZK 6 new features.
Regards.
Asked: 2012-02-15 21:08:00 +0800
Seen: 402 times
Last updated: Feb 26 '12