0

Listbox with ROD, problem setting new Listmodel

asked 2011-07-06 07:37:29 +0800

oziris gravatar image oziris
21

Hi,

I use last version of ZK 5.0.7.1

I have a problem when I set new Model to a listbox. The Listmodel didn't update correctly (scroll bars when not needed, no listitem or wrong listitem)


The way to reproduce :

- create a Listbox (with ROD) with a specified height
- set a ListModel (listbox.setModel(Listmodel model)) with a large dataset (> 500 Listitems) to the Listbox
- Scroll down to the Listbox
- Set a new Listmodel (setModel) with few Listitem (5 Listitems)
- The scroll bar stay a the same position and the Listitems are not correct

Sometimes when you click on a Listitem it refresh correcly the view ... (some event refresh the Listmodel ...)


No problem if you don't use ROD or a small Dataset

I tried to fire event (ListDataEvent.CONTENTS_CHANGED), no effect ...

Do you know a way to refresh the listbox or set to the top the Scroll bar ?

I'll try to post a sample code.

PS : This problem is present only with ROD (org.zkoss.zul.listbox.rod = true) and a list with a size > 100 items

delete flag offensive retag edit

10 Replies

Sort by ยป oldest newest

answered 2011-07-06 08:00:33 +0800

oziris gravatar image oziris
21

updated 2011-07-06 08:12:14 +0800

The sample code :

The problem does not appear if you scroll on the top or bottom ... just in between !

test.zul

<zk xmlns:w="http://www.zkoss.org/2005/zk/client">
	<window id="win" border="none" apply="test.ListboxControl">
		<custom-attributes org.zkoss.zul.listbox.rod="true"/>
		<listbox checkmark="true" multiple="true" id="testListbox" height="400px" width="800px">
			<listhead sizable="true">
				<listheader label="Test"/>
			</listhead>
		</listbox>
		
		<button id="btnNewModel" label="Run Bug (make a scroll to the middle first)"/>
	</window>
</zk>

test/ListboxControl.java (test.ListboxControl)

package test;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;

public class ListboxControl extends GenericForwardComposer {

	private Listbox testListbox;

	/**
	 * 
	 */
	private static final long serialVersionUID = -8768290877229863939L;

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);

		testListbox.setItemRenderer(new ListitemRenderer() {

			@Override
			public void render(Listitem arg0, Object arg1) throws Exception {
				arg0.setValue(arg1);

				DummyItem di = (DummyItem) arg1;

				Listcell lc = new Listcell();

				lc.setLabel(di.getTest());

				lc.setParent(arg0);
			}
		});

		List<DummyItem> ditems = generateDummyItems("First items", 500);

		ListModelList lstModelList = new ListModelList(ditems);

		testListbox.setModel(lstModelList);

	}

	public void onClick$btnNewModel() {
		List<DummyItem> ditems = generateDummyItems("Second items", 5);

		ListModelList lstModelList = new ListModelList(ditems);

		testListbox.setModel(lstModelList);
	}

	public static List<DummyItem> generateDummyItems(String prefix, int size) {

		List<DummyItem> newList = new ArrayList<DummyItem>();

		for (int i = 0; i < size; i++) {
			newList.add(new DummyItem(prefix + i));
		}
		return newList;
	}

	public static class DummyItem {
		protected String test;

		public DummyItem() {

		}

		public DummyItem(String test) {
			setTest(test);
		}

		public String getTest() {
			return test;
		}

		public void setTest(String test) {
			this.test = test;
		}

	}

}

link publish delete flag offensive edit

answered 2011-07-07 01:12:34 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

Hi oziris,
I couldn't reproduce this issue neither with 5.0.7.1 nor with latest build from source. Could you provide a screenshot of how it looks when it is broken or could you provide us an accessible url we could remote debug?

link publish delete flag offensive edit

answered 2011-07-07 01:41:22 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

updated 2011-07-07 03:39:44 +0800

Hi oziris,
Just to clarify. After the step 4 in your test scenario
>>- Set a new Listmodel (setModel) with few Listitem (5 Listitems)
In my test, if I reset model with 5 listitems scroll bar disappears which is what is expected. In case I reset model with 25 list items the scroll bar will be at the bottom which is a default browser behavior.

To give you more idea say for example for the first time you have 500 list items in your listbox and then you scroll to middle so the scrollTop position is set to say 1000px. Now you reset model and have 25 list items in your listbox ZK will not sync scrollTop position to the middle and when browser tries to set scrollTop position to 1000px (which is obviously greater than total listbox height now) scroll will be set to the max position available i.e. at the bottom of listbox. ZK does however auto sync scroll bar position if you select any list item immediately after setting new model.

Hope this give you some idea about what is going on behind the scene.

link publish delete flag offensive edit

answered 2011-07-07 03:42:26 +0800

oziris gravatar image oziris
21

Hi Ashishd,

Thanks for your reply !

You can test the broken behavior here (the same code I post here) :

http://oziris-server.dyndns.org:8080/BugZk/test.zul

But I notice a unwanted behavior with scrollbar anyway .... blank listbox with a wrong scrollbar position (no auto sync scroll bar ...)

The test scenario step-by-step:

- Go to the page : http://oziris-server.dyndns.org:8080/BugZk/test.zul
- Wait the fully loaded page
- Scroll the listbox to the middle
- Wait the new items to be loaded and displayed
- Then click on the button : "Run Bug" (wich simply set a new Listmodel with 5 items)

- What we get : A blank listbox (no items displayed) with a scroll bar in the middle of nowhere ...

- Expected : The Listbox with no scroll bar and 5 items displayed


You can see the correct behavior if you don't scroll the listbox to the middle ....

Tested on IE 7 (target browser for my application), Firefox 5, and Chrome 12, same behavior on all the 3 browser ...

Thanks for your expertise,

link publish delete flag offensive edit

answered 2011-07-07 04:50:33 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

updated 2011-07-07 04:51:33 +0800

Hi oziris,
My bad. My maven dependancies were not updated even after updating to current version so I ended up testing this with wrong ZK version.
Unfortunately this looks like a bug and I have posted it to our issue tracker here. Please follow its progress from there. We will notify you as and when it is fixed. Your test case scenario and smaple code to reproduce is highly appreciated. Thanks.

link publish delete flag offensive edit

answered 2011-07-08 02:49:47 +0800

oziris gravatar image oziris
21

Hi Ashishd,


Thank you for your response.

I will check for the bug tracker.

By the way, is there any work arround ?

For example, the problem doesn't appear if the scroll bar is on top, so is there a way to scroll up to the top to the very first Listitem (but in ROD when we are in the middle the listitem doesn't exist ...) before changing the Listmodel ...

Thanks.

link publish delete flag offensive edit

answered 2011-07-08 03:19:30 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

Hi oziris,
A very quick and bit dirty workaround is to scroll listbox to the top by selecting first listitem and then use echo event to reload listbox model. For example in your ListboxControl.java you can do this

	public void onClick$btnNewModel() {
		testListbox.setSelectedIndex(0);
		Clients.scrollIntoView(testListbox);
		Events.echoEvent("onReload", testListbox, null);
	}
	
	public void onReload$testListbox(Event evt) {
		List<DummyItem> ditems = generateDummyItems("Second items", 5);
		ListModelList lstModelList = new ListModelList(ditems);
		testListbox.setModel(lstModelList);
	}

link publish delete flag offensive edit

answered 2011-07-08 03:52:59 +0800

oziris gravatar image oziris
21

updated 2011-07-08 03:53:38 +0800

Thank you for your answer.

I will try this.

link publish delete flag offensive edit

answered 2011-07-13 20:55:41 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

updated 2011-07-13 21:01:16 +0800

Hi oziris,
this bug was fixed yesterday so you can give the latest freshly a try and see if it works in your environment

Thanks

link publish delete flag offensive edit

answered 2011-07-14 05:18:51 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

Hi oziris,
I noticed a glitch inroduced in this bugfix which also has now fixed so I would recommend you to download today's (7/14) freshly.

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: 2011-07-06 07:37:29 +0800

Seen: 632 times

Last updated: Jul 14 '11

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