问题描述
基于此答案,我尝试将GWT编辑器集成到弹出演示器小部件中.正确的做法是什么?
building on this answer, i try to integrate the GWT editors into a popup presenter widget. What is the right way to do that?
我的视图如下:
public class DeviceEditorDialogView extends
PopupViewWithUiHandlers<DeviceEditorDialogUiHandlers> implements
DeviceEditorDialogPresenterWidget.MyView {
interface Binder extends UiBinder<PopupPanel, DeviceEditorDialogView> {
}
public interface Driver extends SimpleBeanEditorDriver<DeviceDto, DeviceEditorDialogView> {
}
@Inject
DeviceEditorDialogView(Binder uiBinder, EventBus eventBus) {
super(eventBus);
initWidget(uiBinder.createAndBindUi(this));
}
@Override
public SimpleBeanEditorDriver<DeviceDto, ?> createEditorDriver() {
Driver driver = GWT.create(Driver.class);
driver.initialize(this);
return driver;
}
}
我的主持人看起来像这样:
and my presenter looks like this:
public class DeviceEditorDialogPresenterWidget extends PresenterWidget<DeviceEditorDialogPresenterWidget.MyView> implements
DeviceEditorDialogUiHandlers {
@Inject
DeviceEditorDialogPresenterWidget(EventBus eventBus,
MyView view) {
super(eventBus, view);
getView().setUiHandlers(this);
}
/**
* {@link LocalDialogPresenterWidget}'s PopupView.
*/
public interface MyView extends PopupView, DevicesEditView<DeviceDto>, HasUiHandlers<DeviceEditorDialogUiHandlers> {
}
private DeviceDto currentDeviceDTO = null;
private SimpleBeanEditorDriver<DeviceDto, ?> driver;
public DeviceDto getCurrentDeviceDTO() {
return currentDeviceDTO;
}
public void setCurrentDeviceDTO(DeviceDto currentDeviceDTO) {
this.currentDeviceDTO = currentDeviceDTO;
}
@Override
protected void onBind() {
super.onBind();
driver = getView().createEditorDriver();
}
//UiHandler Method: Person person = driver.flush();
}
这是正确的方法吗?什么不见了?目前,当我尝试像这样使用它时,什么也没有发生:
Is this the right approach? What is missing? Currently nothing happens when i try to use it like this:
@Override
public void showDeviceDialog() {
deviceEditorDialog.setCurrentDeviceDTO(new DeviceDto());
addToPopupSlot(deviceEditorDialog);
}
showDeviceDialog在父演示者中,并在单击该父演示者中的按钮时调用,该对话框使用私有的最终DeviceEditorDialogPresenterWidget deviceEditorDialog实例化对话框;
showDeviceDialog is in the parent presenter and called when clicking a button in that parent Presenter, that instantiates the dialog with private final DeviceEditorDialogPresenterWidget deviceEditorDialog;
谢谢!
推荐答案
以下是您上面的代码中缺少的一些关键点:
Here are a few key points that are missing from your code above:
- 您的
DeviceEditorDialogView
应该实现Editor<DeviceDto>
.为了用来自POJO的数据填充DeviceEditorDialogView
字段,这是必需的. - 您的
DeviceEditorDialogView
应该具有映射到POJO中的字段的子编辑器.例如,给定字段deviceDto.modelName
(类型为String
),您可能在DeviceEditorDialogView
中具有名为modelName
的GWTLabel
.此Label
实现Editor<String>
,并且在调用driver.edit(deviceDto)
时将在您的 - 您只能在
DeviceEditorDialogView
的构造函数中调用driver.initialize(this)
一次
DeviceDto
中填充modelName
- Your
DeviceEditorDialogView
should implementEditor<DeviceDto>
. This is required in order for the fields ofDeviceEditorDialogView
to be populated with data from you POJO. - Your
DeviceEditorDialogView
should have child editors that are mapped to fields in your POJO. For example, given the fielddeviceDto.modelName
(typeString
), you could have a GWTLabel
namedmodelName
in yourDeviceEditorDialogView
. ThisLabel
implementsEditor<String>
and will be populated with themodelName
from yourDeviceDto
when you calldriver.edit(deviceDto)
- You should call
driver.initialize(this)
only once, inDeviceEditorDialogView
's constructor
您应该像这样覆盖onReveal()
:
@Override
public void onReveal() {
super.onReveal();
driver.edit(currentDeviceDTO); // this will populate your view with the data from your POJO
}
在您显示DeviceEditorDialogPresenterWidget
之后,将在显示弹出窗口时调用此方法.
This method will be called when the popup is displayed, just after your DeviceEditorDialogPresenterWidget
has been addToPopupSlot
这篇关于GWT的编辑器框架和GWTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!