Announcement

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

    How to load data in ComboBoxItem

    How should specify data source for a ComboBoxItem using DMI to retrieve the data, similar to the sample for grid in smartgwtpro/samples/ds-dmi?
    I would like to be able to load data dynamically in combobox based on what user enters.

    I am using smartgwtpro 2.3 and IE8

    #2
    Not really sure what the question is, but see ComboBoxItem.optionDataSource. A DataSource that serves as an optionDataSource is just an ordinary DataSource - nothing needs to be done differently for such a DataSource as compared to one that is use for eg ListGrid.setDataSource().

    Comment


      #3
      Great. I have implemented the DMI similar to grid and setting the optionDataSource and it works. But now, the data loads automatically. How do I have the data load based on user interaction i.e. when user enters a search string?

      Comment


        #4
        With a ComboBox, you shouldn't see a fetch until the user enters the field, types something and pauses briefly. However note that:
        - a SelectItem fetches immediately in order to support keyboard navigation while the drop-down list is not showing
        - both controls will issue a fetch immediately if they are populated with a value, a displayField is set, and fetchMissingValies is true (the default). They will issue a fetch with criteria specified, in order to get the display value for their logical value. See the soca for fetchMissingValues for details

        Comment


          #5
          Thanks for your previous reply, we have succeeded in using XML datasource for the combobox:
          and now are trying to create datasource in java. Our xml datasource is:

          Code:
          <DataSource ID="comboListItem" serverType="generic">
              <fields>        
                  <field name="tabName" title="Tab Description"/>                        
              </fields>
              <serverObject lookupStyle="new" className="com.trgrp.fits.gui.server.sampleds.ComboListItemDataSource"/>
          </DataSource>
          Now in order to dynamically specify different fields we would like to create datasource programmatically. We have tried using following client-side code:

          Code:
          DataSource comboDs = new DataSource();
          comboDs.setServerConstructor("com.trgrp.fits.gui.server.sampleds.ComboListItemDataSource");
          DataSourceField comboField= new DataSourceField("tabName", FieldType.TEXT, "field label");
          comboDs.addField(comboField);
          comboItem.setOptionDataSource(comboDs);
          We are getting exception on the server, with the message "Can't find dataSource: isc_DataSource_0 - please make sure that you have a isc_DataSource_0.ds.xml file for it in [webRoot]/shared/ds"

          Is that correct way of doing it? We assumed it is trying to put a temporary xml file into [webRoot]/shared/ds and have tried creating that folder, but still getting same error.

          Also: we have noticed that a recent nightly build does not seem to contain DataSource.setServerConstructor(String) method. Is it deprecated?

          Comment


            #6
            You can do this server-side - the most convenient way is to new DataSource.addDynamicDSGenerator().

            If you want to continue with doing it client-side, all that's needed is for the DataSource on the client side to match the server-side ID. Of course, no declarations that drive server-side behavior (operationBindings with custom SQL, requiresRole, etc) will be operable client-side. The server-side behavior will only use the .ds.xml file that is present on the server.

            This is also why serverConstructor does not exist as a client-side API.

            Comment


              #7
              Originally posted by Isomorphic
              With a ComboBox, you shouldn't see a fetch until the user enters the field, types something and pauses briefly. However note that:
              - a SelectItem fetches immediately in order to support keyboard navigation while the drop-down list is not showing
              - both controls will issue a fetch immediately if they are populated with a value, a displayField is set, and fetchMissingValies is true (the default). They will issue a fetch with criteria specified, in order to get the display value for their logical value. See the soca for fetchMissingValues for details
              I have created a combo box item and added a KeyDownHandler on it so that I can mimic a dynamic lookup that would query the server based on something entered by user. My fetch method in my DMI gets called correctly; my debugging tool shows the RPCResponse with the records, but, the combobox will not open with the data. Is there a particular method I should use to open the combo to show the picklist?
              I thought doing a fetch would automatically populate the combobox, but when this didn’t work I tried doing it manually. I have included code snippet to show I am trying to achieve this.

              Code:
              ListGridField tabName = new ListGridField("tabName", "Tab Name");
              		final ComboBoxItem comboItem = new ComboBoxItem();		
              		comboItem.setFetchMissingValues(false);
              		comboItem.setFetchDelay(100000000);		
              		comboItem.setWidth(50);
              		comboItem.setDisplayField("tabName");
              		final DataSource ds1 = DataSource.get("comboListItem");		
              		comboItem.setOptionDataSource(ds1);
              				
              		comboItem.addKeyDownHandler(new KeyDownHandler() {
              			
              			@Override
              			public void onKeyDown(KeyDownEvent event) {
              				
              				String enteredval = (String)event.getItem().getValue();
              				
              				if("Enter".equals(event.getKeyName())){
              					Criteria criteria = new Criteria();
              					criteria.addCriteria("fieldname", enteredval);
              					criteria.addCriteria("resultSetTag", event.getItem().getName()+(new Date()).getTime());
              
              					ds1.fetchData(criteria, new DSCallback() {
              						
              						@Override
              						public void execute(DSResponse response, Object rawData, DSRequest request) {
              							//this correctly returns the number of rows in the data resultset
              							//Window.alert("" + response.getTotalRows());
              														
              							RecordList rl = response.getDataAsRecordList();
              							Map m = new HashMap();
              							m = rl.getValueMap("tabID", "tabName");
              							//This correctly shows me the number of records
              							Window.alert(" " + m.size());
              							comboItem.setValueMap((LinkedHashMap)m);
              							comboItem.redraw();							
              						}
              					});
              				}
              			}
              		});

              Comment


                #8
                There's no way to tell what's wrong from the partial information you've posted, but you shouldn't continue down this path regardless (doesn't support paging, doesn't support client-side filtering, doesn't support cache sync, lots of wasted effort and lots more to maintain - and that's just the tip of the iceberg).

                So far as we can tell, your only complaint about the built-in behavior was that the fetch is happening too early - but you haven't looked into the causes we mentioned (or haven't replied about that).

                Comment


                  #9
                  Originally posted by Isomorphic
                  There's no way to tell what's wrong from the partial information you've posted, but you shouldn't continue down this path regardless (doesn't support paging, doesn't support client-side filtering, doesn't support cache sync, lots of wasted effort and lots more to maintain - and that's just the tip of the iceberg).

                  So far as we can tell, your only complaint about the built-in behavior was that the fetch is happening too early - but you haven't looked into the causes we mentioned (or haven't replied about that).
                  Thanks for the advice and I will take heed; however, I did try using fetchMissingValue(false), but it doesn't help with what I am trying to achieve. I would like to do lookup (query the database) after user type something in combo and then press [ENTER]. How can achieve without doing what I am doing now?

                  Comment


                    #10
                    Ah, OK, the ComboBoxItem is designed around fetching automatically when the user pauses during typing - sounds like you want to explicitly trigger on enter. This is quite different from the ComboBox's default event handling which uses enter to mean that the current highlighted value should be chosen.

                    What you want may be different enough from ComboBoxItem that you just want to base your code off of TextItem. The picklist shown by a ComboBoxItem is basically a customized ListGrid - you could show a similar one yourself, place it underneath the field when the user presses Enter, and use calls to filterData() to filter results.

                    Comment


                      #11
                      Thanks for the last reply pointing us to the direction of custom FormItem. Is there a class to draw a popup that would automatically disappear if user clicks away (bot not if he clicks on the text box)?

                      Comment


                        #12
                        Never mind. I found that Dialog has method setDismissOnOutsideClick() and will try to work with that.

                        Comment

                        Working...
                        X