setSelectedIndex() with Listbox doesn't autoscroll

asked 2009-02-12 20:06:59 +0800

jdeboer gravatar image jdeboer

updated 2009-02-12 20:07:46 +0800

I have a big list and I want to select an item in this list and then scroll the list to this selected item.

I read a lot of message discussing about this issue but no correct solution was given.
The item is correctly selected but I have to scroll myself to this selection.
Using height instead of row doesn't work, I am using Zk 3.5.2.

I have the listbox in the zul:

<listbox id="transactionsList" context="editTransaction" row="50" forward="onSelect=onTransactionSelected">
		<listhead sizable="true">
			<listheader align="center" label="Date"	/>
			<listheader align="center" label="Tiers" />
			<listheader align="center" label="Débit" />
			<listheader align="center" label="Crédit"/>
			<listheader align="center" label="Solde"/>

I am using a GenericAutowireManager which build the list and the model

protected Listbox transactionsList;
protected ListModelList model;

public void onCreate(CreateEvent event){
		model = new ListModelList();
		transactionsRenderer = getTransactionListRenderer();

public void onLoadTransactions (TransactionListEvent event){
		List<Transaction> transactions = event.getTransactions();
		initBalance = event.getInitBalance();
			Transaction transaction = event.getTransaction();
				int index = model.indexOf(transaction);

delete flag offensive retag edit

6 Replies

Sort by » oldest newest

answered 2009-02-12 23:22:42 +0800

HananW gravatar image HananW
160 2

updated 2009-02-12 23:23:25 +0800

Hi jdeboer,

I had the same problem with FF 3 and I opened a bug (it is already fixed but not release in a new version).
You could try to get the fix from ZK svn or use a javascript fix:


function fixListScroll(itemId)
  // Do it asynchronies since ZK still manipulate the list, by setting the timeout to 0
  // we cause the execution to take place immediately after ZK finish it own process.
  setTimeout("fixListScrollDirect('" + itemId + "')", 0);

function fixListScrollDirect(itemId)
  var item = $e(itemId);
  if (!item)
    alert("No item");
  var list = item.parentNode.parentNode.parentNode;

  var viewSize = list.scrollHeight;
  var scrollMax = viewSize - list.offsetHeight;
  if (scrollMax <= 0)
  { // no scroll
  var itemTop = item.offsetTop;
  var itemBottom = itemTop + item.offsetHeight;
  var itemMiddle = itemTop + item.offsetHeight/2;
  var viewTop = list.scrollTop;
  var viewBottom = viewTop + list.offsetHeight;

  if (viewBottom <= itemMiddle || itemBottom <= itemMiddle)
  { // item not in view, scroll so it will be in the middle of the view
    list.scrollTop = Math.max(0, Math.min(scrollMax, itemTop - (list.offsetHeight - item.offsetHeight)/2));
  { // make sure that all the item is viewable
    var delta = 0;
    if (itemBottom > viewBottom)
      dalta = itemBottom - viewBottom;
      viewTop += delta;
      viewBottom += delta;
    if (itemTop < viewTop)
      delta -= (viewTop - itemTop);
    list.scrollTop += delta;

and in your java code add the following:
Clients.response(new AuScript(transactionsList, "fixListScroll('" + transactionsList.getSelectedItem().getUuid() + "')"));

of course in the zul page you have to inclue the fixZk.js:

<script type="text/javascript" src="/js/fixZk.js"/>

Maybe there are better ways to do it, but currently this works great for me.

link publish delete flag offensive edit

answered 2009-02-25 21:04:04 +0800

jdeboer gravatar image jdeboer

Ok thank you HananW, I will wait until the new release.
It is right that I didn't try with browser other than FF3.

link publish delete flag offensive edit

answered 2009-03-08 21:53:34 +0800

jdeboer gravatar image jdeboer

I have just downloaded zk 3.6.0 (which was just released few days ago) and the bug is still there. I am wondering if zk is a mature product. I found another bug (which in my opinion is really annoying). It is impossible to select some date like 25th Feb (with the datebox component). It displays 25th of March. At this point, zk is really unusable for me...

link publish delete flag offensive edit

answered 2009-03-09 01:29:05 +0800

hideokidd gravatar image hideokidd
750 1 2


I'm sorry that the problem still existed in ZK 3.6.0,
would you please provide an example to show this bug about datebox ?


link publish delete flag offensive edit

answered 2009-03-30 12:58:04 +0800

jdeboer gravatar image jdeboer

The datebox was recently fixed. Finally, it occured only with the format date ( dd MMM yyyy) with MMM is the month name (Jan, Feb ...) and I think only with the locale FR. Probably caused by the fact that in French, some month have accents (such as Fév, Déc....).

However, the autoscroll bug is still opened and no one seems to be in charge. That is more annoying...

link publish delete flag offensive edit

answered 2009-03-30 16:40:48 +0800

hideokidd gravatar image hideokidd
750 1 2

updated 2009-03-30 16:42:17 +0800


Please refer to the discussion

The last message may help.

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




Asked: 2009-02-12 20:06:59 +0800

Seen: 495 times

Last updated: Mar 30 '09

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