Announcement

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

    ComboBoxItem as EditorType of ListGridField

    SmartGWT 2.2 gpl
    NetBeans 6.9.1
    GWT 2.0.4
    Mozilla Firefox

    Dear community,

    I need to allow the user to pick an element from a datasource-linked list giving the possibility of entering a new item (combobox style).
    When the user makes his choice I need to get the entire record selected, well I didn't succeed in it through the method getSelectedRecord associated to the event.getItem() inside ChangeHandler.

    Code:
    Code:
    private final ListGridField fileName = new ListGridField( "fileName", "Select from the List" );
    
    ...
    
    //final SelectItem itemEditor = new SelectItem();
    final ComboBox itemEditor = new ComboBox();
    itemEditor.setFilterLocally( true );
    itemEditor.setAddUnknownValues( true );
    
    itemEditor.setPickListFilterCriteriaFunction(
      new FilterCriteriaFunction() {
        public Criteria getCriteria() {
          if ( project == null ){
            IWDebug.error( "project is null ");
            return ProjectRecord.getFilterAllMODs();
          }
    
          return project.getMODCriteria();
        }
      }
    );
    //itemEditor.setOptionDataSource( IWStructure.getUser().getMODList() );
    fileName.setOptionDataSource( IWStructure.getUser().getMODList() );
    Code:
    fileName.addChangedHandler(
     new ChangedHandler() {
      public void onChanged( final ChangedEvent event ) {
       if ( event == null )
        return;
    
       if ( event.getItem() == null ){
        return;
    
       IWDebug.notice( "event.getItem class: " + event.getItem().getClass().getName() );
    
       final Record record = event.getItem().getSelectedRecord();
    
       if ( record == null ){
        IWDebug.message( "No known output file selected." );
        /*It means that user want to specify the name of a new file*/
        return;
      }
    
      final String fileID = record.getAttribute( "modID" );
      IWDebug.message( "fileID: " + fileID );
      IWDebug.message( "file Name: " + record.getAttribute( "fileName" ) );
    
      final ModelRecord model = new ModelRecord( record );
      model.setFileID( fileID );
      }
     }
    );
    Well, even if I choose a file from the list, the record got from event.getItem().getSelectedRecord() is always null.

    I made several trials:

    - If I use SelectItem instead of ComboBoxItem, it works: I can successfully read the record associated to the selection.
    - If I override the method getSelectedRecord of my combobox as suggested in several posts
    Code:
    @Override
    public native ListGridRecord getSelectedRecord() /*-{
     var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
     var ret = self.getSelectedRecord();
     if(ret == null || ret === undefined) return null;
      var retVal = @com.smartgwt.client.core.RefDataClass::getRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
     if(retVal == null) {
      retVal = com.smartgwt.client.widgets.grid.ListGridRecord::new(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
     }
     return retVal;
    }-*/;
    I can appreciate no changes.
    - No changes even if I set the datasource directly to the ComboBoxItem.

    I'm currently using SelectItem as a temporary patch but I would really appreciate any suggestion of work-around.

    Yary Ribero

    #2
    Further details:

    I found out that event.getItem()'s type is TextItem in both cases of editor choice (SelectItem or ComboBoxItem). I still can't figure why getSelectedRecord works in a case and not in another.

    Comment


      #3
      "When you supply a custom FormItem via setEditorType(), you're really providing properties which are then used to create multiple FormItems (eg, in grids, forms and trees) and there's an underlying limitation here where event handlers have to be written to dynamically receive the actual FormItem rather than relying on "this" (because there's more than one "this").

      To get an actual handle on the formItem, use the FormItem instance from an event obtained via getItem()."

      Also see this post.

      Comment

      Working...
      X