Announcement

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

    How to add a callback to the fetch fired from option datasource

    I am trying to get the loaded data(Record objects) in a Comboboxitem. I set an option data source to the combobox item.
    Now according the Formitem.optionDatasource documentation,

    The data will be retrieved via a "fetch" operation on the DataSource, passing the pickListCriteria (if set) as criteria, and passing optionFilterContext (if set) as DSRequest properties.


    I wanted to know is there any way i can add a callback to the above fetch operation that was fired during init,so that i can have the records that are loaded into the combobox ?

    I am asking this because, when user selects a record from comboboxitem, i want to extract the selected record (Record object) so that i get pull other attributes apart from displayFiled and valueField.

    I tried to achieve this via event.getItem().getSelectedRecord() , however again the doc's says that return value for the method getSelectedRecord will be null until the fetch completes( in which case how can i get the record) or there is no match.

    Code:
    ComboBoxItem selectFileItem = new ComboBoxItem("fileSelect", "ComboBox");
    		selectFileItem.setAutoFetchData(true);
    		selectFileItem.setHideEmptyPickList(false);
    		selectFileItem.setAddUnknownValues(Boolean.FALSE);
    		selectFileItem.setWrapTitle(false);
    		selectFileItem.setRequired(true);
    		selectFileItem.setColSpan(5);
    		selectFileItem.setWidth(745);
    		selectFileItem.setOptionDataSource(myOptionDataSource);
    		selectFileItem.setValueField(myOptionDataSource.KEY);
    		selectFileItem.setDisplayField(myOptionDataSource.DESCRIPTION);
    
    selectFileItem.addChangeHandler(new ChangeHandler() {
    			
    @Override
    public void onChange(ChangeEvent event) {
       event.cancel();
       if(event.getValue() != null) {
        Record record = event.getItem().getSelectedRecord(); //[b] this line is returning null[/b]
    ......
    			}
    }

    SmartClient version:
    SC_SNAPSHOT-2011-12-05/LGPL Development Only (built 2011-12-05)
    Browser : Chorme 32.0.1

    #2
    Hi chebus,

    did you already read the addChangeHandler(...) javadocs? It says there: "Note that if you ask the form for the current value in this handler, you will get the old value because the change has not yet been committed. The new value is available as a parameter to this method."

    Most likely you'll want to use FormItem.addChangedHandler(...).

    Regarding your "that i can pull other attributes apart from displayFiled and valueField". Did you see setPickListProperties(ListGrid listGrid)? You can define a "ListGrid" there. Set all you extra ListGridFields to ListGridField.setHidden(true) and set ComboBoxItem.setPickListHeaderHeight(0) to archive "normal" DropDown design.

    Best regards,
    Blama

    Comment


      #3
      DataArrived fires when data comes back from the automatic fetch.

      Comment


        #4
        Thanks Isomorphic for the suggestion,that worked!

        Blama
        Thank you for the advice!

        "Note that if you ask the form for the current value in this handler, you will get the old value because the change has not yet been committed. The new value is available as a parameter to this method."

        Not sure what exactly is current value, however, event.getValue inside change handler returns new value.
        Also fileSelectItem.getValue/getDisplayValue returns the current value that is displayed.

        for instance ,

        Code:
        selectFileItem.addChangeHandler(new ChangeHandler() {
        			
        @Override
        public void onChange(ChangeEvent event) {
          event.cancel();
          if(event.getValue() != null) 
          { // control will reach here if the user tries to select a value.
        }
           
        }

        Comment


          #5
          Hi Isomorphic,
          Can you please confirm if the behaviour described in my previous post is as expected.

          Comment

          Working...
          X