Using GWT Editor Framework with CellList
Asked Answered
R

0

11

I want to use the GWT Editor framework with a CellList. My data model looks like this:

public class CarDto {
   private String name;
   private List<String> features;
   // getter and setter
}

Using GWTP here is part of my presenter:

public class Presenter {

  public interface MyView extends View, Editor<CarDto> {
  }

  private final SimpleBeanEditorDriver<CarDto, ?> editorDriver;

  public Presenter(...) {
      editorDriver = getView().createEditorDriver();
  } 
  ...

  @Override
  public void saveButtonClicked() { 
    CarDto carDto = editorDriver.flush();
    int size = carDto.getFeatures().size();  // result is 0
  }

}

My View class:

public class CarView implements Presenter.MyView {

   public interface EditorDriver extends SimpleBeanEditorDriver<CarDto, CarView> {   
   }


   @Path(value="name")
   @UiField
   TextBox nameInput;   // editor works fine with this

   @Path(value="features")   // this editor is not working !!!
   ListEditor<String, LeafValueEditor<String>> featuresEditor;

   @UiField
   CellList<String> cellList;  
   ListDataProvider<String> dataProvider;

   public CarView() {
     dataProvider = new ListDataProvider<String>();
     dataProvider.addDataDisplay(cellList);
     featuresEditor = HasDataEditor.of(cellList);
   }


   // create the editor driver
   @Override
   public SimpleBeanEditorDriver<CarDto, ?> createEditorDriver() {
     EditorDriver driver = GWT.create(EditorDriver.class);
     driver.initialize(this);
     return driver;
   }


  @UiHandler("save")
  protected void saveClicked(ClickEvent e) {
    List<String> dtos = dataProvider.getList();
    dtos.add("test");
    getUiHandlers().saveButtonClicked();
  }
}

When I hit save button and do editorDriver.flush() in my presenter than I only get the name property from the view's CarDto. The list of features is always empty.

I have to change the value of the featuresEditor manually like this:

featuresEditor.getList().add(...);

in order to get a change in the List after I flush it. This would mean that I have to set two lists to maintain the data:

featuresEditor.getList().add(...);
dataProvider.getList().add(...);

this does not seems to be correct.

How can I achieve that the ListEditor is updated correctly when the dataProvider list changes? How do I setup an Editor correctly to work with the List<String> which is handled by a CellList?

Rufus answered 29/1, 2016 at 17:20 Comment(3)
duplicate? #13749086Jackinthebox
From what I've heard the cell widgets don't play well with the editor framework, but I believe you want a HasDataEditor, don't you?Ilise
Try changing your ListEditor<String, LeafValueEditor<String>> to a HasDataEditor<String>?Ilise

© 2022 - 2024 — McMap. All rights reserved.