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

Wrong model selection in onChange of combobox

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: 6.5.0
    • Fix Version/s: 6.5.1
    • Component/s: Components
    • Labels:
      None

      Description

      <zk>
      	<label multiline="true">
      		1.select on comobobx1 by mouse, the onSelect and onChange should has same selection on model and selected item
      		2.select on combobox2 by mouse, the onSelect  and onChange should has same model selection
      		  (it fail on 2 if the bug is not fixed, you will see model selection always show previous selection if you don't call 
      		  combobox.getSelectedItem in onChange)
      	</label>
      	<zscript><![CDATA[//@DECRATION
      	    class Item {
      	    	String name;
      	    	public Item(String name){this.name = name;}
      	    	public String getName(){
      	    		return name;
      	    	}
      	    }
                        
      		java.util.List list = new java.util.ArrayList();
      		list.add(new Item("option 1"));
      		list.add(new Item("option 2"));
      		list.add(new Item("option 3"));
      		list.add(new Item("option 4"));
      		list.add(new Item("option 5"));
      		org.zkoss.zul.ListModelList lm1 = new org.zkoss.zul.ListModelList(list);
      		org.zkoss.zul.ListModelList lm2 = new org.zkoss.zul.ListModelList(list);
      		void onSelect(org.zkoss.zul.Combobox cb, boolean showSelectedComponent) {
      			org.zkoss.zul.ListModelList m = cb.getModel();
      			String msg;
      			java.util.Set selection = m.getSelection();
      			org.zkoss.zul.Comboitem selectedItem = showSelectedComponent?cb.getSelectedItem():null;
      			if(selection.size()>0){
      				Item sel = m.getSelection().iterator().next();
      				msg = "model selection : "+ sel.name;
      			}else{
      				msg = "no model selection";
      			}
      //			msg += ", combox value : "+cb.getValue();
      			if(showSelectedComponent){
      				msg += ", selected item : "+(selectedItem==null?"null":selectedItem.getValue().name);
      			}
      			msg += ":"+new java.util.Date();
      			System.out.println(">>>onSelect>>"+msg);
      			lb1.setValue(msg);
      		}
      		void onChange(org.zkoss.zul.Combobox cb, boolean showSelectedComponent) {
      			org.zkoss.zul.ListModelList m = cb.getModel();
      			String msg;
      			java.util.Set selection = m.getSelection();
      			org.zkoss.zul.Comboitem selectedItem = showSelectedComponent?cb.getSelectedItem():null;
      			if(selection.size()>0){
      				Item sel = m.getSelection().iterator().next();
      				msg = "model selection : "+ sel.name;
      			}else{
      				msg = "no model selection";
      			}
      //			msg += ", combox value : "+cb.getValue();
      			if(showSelectedComponent){
      				msg += ", selected item : "+(selectedItem==null?"null":selectedItem.getValue().name);
      			}
      			msg += ":"+new java.util.Date();
      			System.out.println(">>>onChange>>"+msg);
      			lb2.setValue(msg);
      		}
      	]]></zscript>
      	<hlayout>
      	<vlayout>
      		<combobox id="cb1" model="${lm1}" onSelect='onSelect(cb1,true)' onChange='onChange(cb1,true)' >
      			<template name="model">
      				<comboitem label="${each.name}" />
      			</template>
      		</combobox>
      		<combobox id="cb2" model="${lm2}" onSelect='onSelect(cb2,false)' onChange='onChange(cb2,false)' >
      			<template name="model">
      				<comboitem label="${each.name}" />
      			</template>
      		</combobox>
      	</vlayout>
      	<vlayout>
      	<hlayout>onSelect:<label id="lb1" /></hlayout>
      	<hlayout>onChange:<label id="lb2" /></hlayout>
      	</vlayout>
      	</hlayout>
      	
      </zk>
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              vincentjian vincentjian
              Reporter:
              dennis dennis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: