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
?
ListEditor<String, LeafValueEditor<String>>
to aHasDataEditor<String>
? – Ilise