Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-1538

IndexOutOfBoundsException when use live ListModelList

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Normal Normal
    • None
    • 6.5.1
    • Components
    • None

      Not sure it is out of spec or ZK should tolerate this.

      <zk>
      	<label multiline="true">
      	Issue : get IndexOutOfBoundsException
      	1.click select, it will select last one
      	2.click delete, it will remove last one (get exception here if bug doesn't fixed)
      	
      	</label>
      	<div width="400px" >
      		<listbox id="listbox" mold="paging" pageSize="10">
      			<listhead>
      				<listheader label="name" />
      			</listhead>
      			<template name="model" >
      				<listitem>
      					<listcell label="${each.name}" />
      				</listitem>
      			</template>
      		</listbox>
      		<button label="select" onClick="select()"/>
      		<button label="delete" onClick="delete()"/>
      	</div>
      <zscript><![CDATA[
      	//set to false will avoid it, 
      	//however MVVM use liveModel..
          boolean useLive = true;               
                        
      	class Item {
      		String name;
      		public Item() {
      			
      		}
      		public Item(String name) {
      			this.name = name;
      		}
      
      		public String getName() {
      			return name;
      		}
      
      		public void setName(String name) {
      			this.name = name;
      		}
      		
      	}
      	List itemList = new LinkedList();
      	for (int i = 0; i < 10; i++) {
      		itemList.add(new Item("item " + i));
      	}
      	ListModelList listModelList = new ListModelList(itemList,true);//if use live list
      	listbox.setModel(listModelList);
      	
      	Item selected;
      	public void select(){
      		listModelList.addToSelection(selected = itemList.get(itemList.size()-1));
      	}
      	public void delete(){
      		//remove selected for original list
      		itemList.remove(selected);
      				
      		//make a non existed object into selection		
      		selected = new Item("A");
      		listModelList.addToSelection(selected);
      		
      		//update the model
      		listbox.setModel(listModelList = new ListModelList(itemList,true));
      	}
      ]]>
      </zscript>
      </zk>
      

      >>java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
      >> at java.util.LinkedList.entry(LinkedList.java:365)
      >> at java.util.LinkedList.get(LinkedList.java:315)
      >> at org.zkoss.zul.ListModelList.getElementAt(ListModelList.java:150)
      >> at org.zkoss.zul.Listbox.doSelectionChanged(Listbox.java:2580)
      >> at org.zkoss.zul.Listbox.onListDataChange(Listbox.java:2534)
      >> at org.zkoss.zul.Listbox.access$17(Listbox.java:2521)
      >> at org.zkoss.zul.Listbox$4.onChange(Listbox.java:461)
      >> at org.zkoss.zul.AbstractListModel.fireEvent(AbstractListModel.java:61)
      >> at org.zkoss.zul.ListModelList.fireSelectionEvent(ListModelList.java:438)
      >> at org.zkoss.zul.AbstractListModel.addToSelection(AbstractListModel.java:130)
      >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      >> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      >> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      >> at java.lang.reflect.Method.invoke(Method.java:597)
      >> at bsh.Reflect.invokeMethod(Unknown Source)
      >> at bsh.Reflect.invokeObjectMethod(Unknown Source)
      >> at bsh.Name.invokeMethod(Unknown Source)
      >> at bsh.BSHMethodInvocation.eval(Unknown Source)
      >> at bsh.BSHPrimaryExpression.eval(Unknown Source)
      >> at bsh.BSHPrimaryExpression.eval(Unknown Source)
      >> at bsh.BSHBlock.evalBlock(Unknown Source)
      >> at bsh.BSHBlock.eval(Unknown Source)
      >> at bsh.BshMethod.invokeImpl(Unknown Source)
      >> at bsh.BshMethod.invoke(Unknown Source)
      >> at bsh.BshMethod.invoke(Unknown Source)
      >> at bsh.Name.invokeLocalMethod(Unknown Source)
      >> at bsh.Name.invokeMethod(Unknown Source)
      >> at bsh.BSHMethodInvocation.eval(Unknown Source)
      >> at bsh.BSHPrimaryExpression.eval(Unknown Source)
      >> at bsh.BSHPrimaryExpression.eval(Unknown Source)
      >> at bsh.Interpreter.eval(Unknown Source)
      >> at bsh.Interpreter.eval(Unknown Source)
      >> at org.zkoss.zk.scripting.bsh.BSHInterpreter.exec(BSHInterpreter.java:131)
      >> at org.zkoss.zk.scripting.util.GenericInterpreter.interpret(GenericInterpreter.java:328)
      >> at org.zkoss.zk.ui.impl.PageImpl.interpret(PageImpl.java:875)
      >> at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2701)
      >> at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2654)
      >> at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
      >> at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1710)
      >> at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1495)
      >> at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1205)
      >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:583)
      >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:481)
      >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:489)
      >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      >> at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
      >> at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
      >> at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      >> at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
      >> at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
      >> at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
      >> at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      >> at org.mortbay.jetty.Server.handle(Server.java:326)
      >> at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
      >> at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)
      >> at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
      >> at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
      >> at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      >> at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
      >> at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

            Unassigned Unassigned
            dennis dennis
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: