0

Strange api contract for ListModelList.listIterator in zk5.07

asked 2011-05-16 10:30:10 +0800

cvarona gravatar image cvarona
554 1 6

Hi there,

after realizing a list iterator obtained by invoking listIterator() on a ListModelList instance failed to update the underlying listbox upon item removal I gazed into the source code just to find that listIterator() != listIterator( 0 ):

	public ListIterator listIterator() {
		return _list.listIterator();
	}
	
	public ListIterator listIterator(final int index) {
		return new ListIterator() {
			private ListIterator _it = _list.listIterator(index);
			private Object _current = null;
			public boolean hasNext() {
				return _it.hasNext();
			}
			public Object next() {
				_current = _it.next();
				return _current;
			}
			public void remove() {
				final int index = _list.indexOf(_current);
				if (index >= 0) {
					removeSelection(_current);
					_it.remove();
					fireEvent(ListDataEvent.INTERVAL_REMOVED, index, index);
				}
			}
			public void add(Object arg0) {
				final int index = _it.nextIndex();
				_it.add(arg0);
				fireEvent(ListDataEvent.INTERVAL_ADDED, index, index);
			}
			public boolean hasPrevious() {
				return _it.hasPrevious();
			}
			public int nextIndex() {
				return _it.nextIndex();
			}
			public Object previous() {
				_current = _it.previous();
				return _current;
			}
			public int previousIndex() {
				return _it.previousIndex();
			}
			public void set(Object arg0) {
				final int index = _list.indexOf(_current);
				if (index >= 0) {
					_it.set(arg0);
					fireEvent(ListDataEvent.CONTENTS_CHANGED, index, index);
				}
			}
		};
	}

Such a behaviour is rather counterintuitive for me, specially because the javadoc does not say anything about this difference (wheter really meant for or just introduced by mistake).

With kind regards

César Varona

delete flag offensive retag edit

3 Replies

Sort by » oldest newest

answered 2011-05-26 00:02:34 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi cvarona,
What of ZK version do you using?

link publish delete flag offensive edit

answered 2011-05-26 02:34:28 +0800

cvarona gravatar image cvarona
554 1 6

Hi,

just zk5.0.7, as stated.

With kind regards

César Varona

link publish delete flag offensive edit

answered 2011-05-30 20:38:01 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi cvarona,
Thanks for you suggestion, I have checkin the modify.

public ListIterator listIterator() {
	return listIterator(0);
}

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-05-16 10:30:10 +0800

Seen: 273 times

Last updated: May 30 '11

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