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

Chosenbox getSelectedObjects() returns empty list if model is ListModel of JavaBean instances instead of ListModel of String

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: 6.5.3
    • Fix Version/s: 6.5.4
    • Component/s: None
    • Security Level: Jimmy
    • Labels:

      Description

      Chosenbox allows setting ListModel. however if used with ListModel of Javabean instances instead of ListModel of String instances, getSelectedObjects() does not return the list of currently selected Javabean objects. This maybe because Chosenbox does not have any children components like Combobox has. However there should be some way to match Chosenbox labels with assigned ListModel Javabean instances and it should be handled by Chosenbox.

        Issue Links

          Activity

          Hide
          jumperchen jumperchen added a comment -

          we cannot reproduce this issue with the following example,

          <zk>
          	<zscript><![CDATA[
          
             	public class Bean {
             		String _name;
             		public Bean(String name) {
             			_name = name;
             		}
             		public String toString() {
             			return _name;
             		}
             	}
          	List lst = Arrays.asList(new Bean[] { new Bean("first"), new Bean("second"), new Bean("third") });
          
          	
          	ListModel model = new ListModelList(lst);
          ]]></zscript>
          	<chosenbox id="cbx" width="500px" model="${model}"/>
          	<button id="btn" label="getSelectedObject()" onClick='alert(cbx.getSelectedObjects().toString());'/>
          </zk>
          
          Show
          jumperchen jumperchen added a comment - we cannot reproduce this issue with the following example, <zk> <zscript><![CDATA[ public class Bean { String _name; public Bean( String name) { _name = name; } public String toString() { return _name; } } List lst = Arrays.asList( new Bean[] { new Bean( "first" ), new Bean( "second" ), new Bean( "third" ) }); ListModel model = new ListModelList(lst); ]]></zscript> <chosenbox id= "cbx" width= "500px" model= "${model}" /> <button id= "btn" label= "getSelectedObject()" onClick='alert(cbx.getSelectedObjects().toString());'/> </zk>
          Hide
          ashishd ashishd added a comment -

          If you don't implement toString() method then it return empty list. User should not have to implement toString method for this feature to work properly. without toString() on bean object the correct way to provide rendering would be to implement a ItemRenderer as shown below (but it should return selected objects not an empty list)

          <zk>
          	<zscript><![CDATA[
          	import org.zkoss.zul.ItemRenderer;
             	public class Bean {
             		String _name;
             		public Bean(String name) {
             			_name = name;
             		}
             		
             		public String getName() {
             			return _name;
             		}
             	}
          	List lst = Arrays.asList(new Bean[] { new Bean("first"), new Bean("second"), new Bean("third") });
          	
          	public class NameRenderer implements ItemRenderer {
          		public String render(Component owner, Object data, int index)
          				throws Exception {
          			Bean b = (Bean) data; 
          			return b.getName();
          		}
          	}
          	ItemRenderer nameRenderer = new NameRenderer();
          	
          	ListModel model = new ListModelList(lst);
          ]]></zscript>
          	<chosenbox id="cbx" width="500px" model="${model}" itemRenderer="${nameRenderer}"/>
          	<button id="btn" label="getSelectedObject()" onClick='alert(cbx.getSelectedObjects());'/>
          </zk>
          
          Show
          ashishd ashishd added a comment - If you don't implement toString() method then it return empty list. User should not have to implement toString method for this feature to work properly. without toString() on bean object the correct way to provide rendering would be to implement a ItemRenderer as shown below (but it should return selected objects not an empty list) <zk> <zscript> <![CDATA[ import org.zkoss.zul.ItemRenderer; public class Bean { String _name; public Bean(String name) { _name = name; } public String getName() { return _name; } } List lst = Arrays.asList(new Bean[] { new Bean( "first" ), new Bean( "second" ), new Bean( "third" ) }); public class NameRenderer implements ItemRenderer { public String render(Component owner, Object data, int index) throws Exception { Bean b = (Bean) data; return b.getName(); } } ItemRenderer nameRenderer = new NameRenderer(); ListModel model = new ListModelList(lst); ]]> </zscript> <chosenbox id= "cbx" width= "500px" model= "${model}" itemRenderer= "${nameRenderer}" /> <button id= "btn" label= "getSelectedObject()" onClick='alert(cbx.getSelectedObjects());'/> </zk>
          Hide
          jumperchen jumperchen added a comment -

          Bug fixed since 9/2/2013

          Show
          jumperchen jumperchen added a comment - Bug fixed since 9/2/2013
          Hide
          daquan198163 daquan198163 added a comment -

          With the 6.5.4,getSelectedObjects() can return String list ,
          but it should reaturn JavaBean list!!!!!

          Show
          daquan198163 daquan198163 added a comment - With the 6.5.4,getSelectedObjects() can return String list , but it should reaturn JavaBean list!!!!!

            People

            • Assignee:
              jumperchen jumperchen
              Reporter:
              ashishd ashishd
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: