Controlling Listbox select behaviour

asked 2008-09-25 18:50:20 +0800

ansancle gravatar image ansancle
317 9

I have run into an issue with the Listbox selection model. The way the listbox works is if you select a row, then click it again, you DO NOT receive the onSelect for the second click. I am trying to change the way the selection works for a multi-select listbox I have.
What I want is the first click on a row to select it, the second click on the same row to deselect it - this is easy to do if the second click triggered the onSelect handler - but it doesn't. I have looked at the methods in the parent for a way to intercept the mouse event and couldn't see anything obvious.
My question - How can I make each click on a row trigger the onSelect handler, regardless of whether I already click on that row or not?

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2008-09-26 00:58:07 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Please use the onClick event instead.

link publish delete flag offensive edit

answered 2008-09-26 13:14:36 +0800

ansancle gravatar image ansancle
317 9

It appears that the listbox does not respond to the onClick event. I tried the following since I am using a Composer.
The id of my listbox in the .zul is _zonesListBox and the associated Listbox member of my composer is _zonesListBox :

public void onClick$_zonesListBox(Event event)

I also tried in the ZKDemo just to test using the attribute tag in a listbox :

<listbox width="250px">
    <attribute name="onClick">.........

And this was never called either. When I changed the attribute to onSelect it was called.

Here is my full .zul (dhZoneListbox overrides Listbox in lang-addon.xml)

<dhITouchWindow id="DHzZonesWindow" apply="com.dh.ui.itouch.composer.zone.DHzZonesComposer">
		<dhZoneListbox multiple="true" style="margin-bottom:5px" width="100%" id="_zonesListBox"/>	
		<button label="OK" id="_okButton"/>

And here is the relevant portions of the Composer :

public class DHzZonesComposer extends GenericForwardComposer implements Initiator
	private static final Logger logger = Logger.getLogger(DHzZonesComposer.class);
	private DHzZoneModel _zoneModel = new DHzZoneModel();
	private DHzZoneList _zonesListBox;
	private Button _okButton;

	 * Method : onClick$_zonesListBox
	 * @param event
	public void onClick$_zonesListBox(Event event)

link publish delete flag offensive edit

answered 2008-09-26 13:23:32 +0800

ansancle gravatar image ansancle
317 9

More info, I added in my composer as an eventListener to the listbox (this is the composer)

_zonesListBox.addEventListener("onClick", this);

And in the onEvent handler of the composer the following code. This get's called same as the onSelect, if you select one row then another it gets called, if you try and select the same row twice, the first click generates an event, the second does not.

	 * Method : onEvent
	 * @see org.zkoss.zk.ui.event.GenericEventListener#onEvent(org.zkoss.zk.ui.event.Event)
	 * @param arg0
	 * @throws Exception
	public void onEvent(Event event) throws Exception
		logger.info("DHzZonesComposer::onEvent, Event Name = " + event.getName());

link publish delete flag offensive edit

answered 2008-09-29 13:45:51 +0800

ansancle gravatar image ansancle
317 9

I have tried in the Debugger to find where the event is getting swallowed the second time you click a row in the listbox, can one of the ZK team please let me know which class is intercepting the mouse event and then deciding not to pass it along?
I walked the call stack trying to set breakpoints to capture it so I can change the behavior with no luck.
Neither onClick nor onSelect get passed along if a row is already selected, help greatly appreciated,

link publish delete flag offensive edit

answered 2008-10-02 04:07:27 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

The onClick event listener shall be set on Listitem, not on Listbox.

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: 2008-09-25 18:50:20 +0800

Seen: 513 times

Last updated: Oct 02 '08

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