我想将GWT编辑器框架与CellList一起使用。我的数据模型如下所示:
public class CarDto {
private String name;
private List<String> features;
// getter and setter
}
在这里使用GWTP是我的演示者的一部分:
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
}
}
我的观点课程:
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();
}
}
当我点击“保存”按钮并在演示者中执行editorDriver.flush()
时,我只能从视图name
获取CarDto
属性。功能列表始终为空。
我必须像这样手动更改featuresEditor
的值:
featuresEditor.getList().add(...);
在我刷新后在List中进行更改。这意味着我必须设置两个列表来维护数据:
featuresEditor.getList().add(...);
dataProvider.getList().add(...);
这似乎不正确。
当dataProvider列表更改时,如何才能实现ListEditor的正确更新?如何正确设置编辑器以使用由List<String>
处理的CellList
?