Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Assign Multiple SelectItem to DataSource

    Hi,

    I just have a question... is it possible to assign the following SelectItem to a dataSource?

    Code:
                LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
                map.put("10", "car";
                map.put("20", "bike");
                map.put("30", "bus");
    
                SelectItem item = new SelectItem("item", "item");
                item.setValueMap( map );
                item.setMultiple( true );
    For storing the values I call:
    Code:
                item.getValuesAsString();
    This methode provides me a result String like
    Code:
                10,20,30
    In my datasource I use the following

    Code:
            DataSourceTextField itemField = new DataSourceTextField("item", "item");
            itemField.setMultiple( true );
    But the datasource assignment does not work. Values are not selected. The string "10,20,30" appears as value in the combobox.

    I used
    martGWT: 6.1p (Build Sat, 02.12.2017)
    OP: Ubuntu
    Browser: Chrome

    Thanks
    Andy



    #2
    Yes, you can use a DataSource with a multiple select. See DataSourceField.multipleStorage.

    Comment


      #3
      Thanks for responding... but isn't this what I did?

      Code:
      LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();            
      map.put("1", "car";            
      map.put("2", "bike");            
      map.put("3", "bus");              
      
      DataSourceTextField typesField = new DataSourceTextField( "types", "types");            
      typesField.setMultiple( true );            
      typesField.setMultipleValueSeparator( "," );            
      typesField.setValueMap( map );              
      
      SelectItem comboType = new SelectItem( "types" );            
      comboType.setMultiple( true );            
      comboType.setMultipleValueSeparator( "," );            
      comboType.setMultipleAppearance( MultipleAppearance.PICKLIST );            
      comboType.setValueMap( map );
      With the above mentioned code... there are not items selected in the SelectItem. Only the IDs appear in the combo as String (See Screenshot).

      Click image for larger version  Name:	multiple.png Views:	1 Size:	1.4 KB ID:	252337

      My values comes in via Restful/Json as follows:

      Code:
       
       "types":"2,3"
      Last edited by andyx1975; 19 Mar 2018, 03:13.

      Comment


        #4
        See docs - the expected value for a field that is multiple:true is an array of values, not a comma-separated string. In UI controls and when retrieved from a DataSource is this format. multipleStorage applies only at the point that the server framework is storing to SQL or Hibernate.

        Comment

        Working...
        X