如何将附加数据传递给GWT子编辑器?
我有一个问题: 我有一个PresenterWidget,其中包含子编辑器。 有一些“容器”元素应该可以被这个小部件编辑。这些容器可以分配给组。为此,我想从服务器获取所有可用组的列表。因此,小部件的设置如下(我使用GWTP):如何将附加数据传递给GWT子编辑器?,gwt,gwtp,Gwt,Gwtp,我有一个问题: 我有一个PresenterWidget,其中包含子编辑器。 有一些“容器”元素应该可以被这个小部件编辑。这些容器可以分配给组。为此,我想从服务器获取所有可用组的列表。因此,小部件的设置如下(我使用GWTP): 公共类ContainerEditorDialogPresenterWidget扩展了PresenterWidget实现 ContainerEditorDialoguiHandler{ 私人最终配售经理配售经理; private List groupList=new Arra
公共类ContainerEditorDialogPresenterWidget扩展了PresenterWidget实现
ContainerEditorDialoguiHandler{
私人最终配售经理配售经理;
private List groupList=new ArrayList();
专用最终调度异步调度;
@注入
ContainerEditorDialogPresenterWidget(EventBus EventBus,
MyView视图、PlaceManager PlaceManager、DispatchAsync dispatcher){
超级(事件总线、视图);
getView().setUiHandlers(此);
this.dispatcher=dispatcher;
fetchGroups();
}
...
公共组(){
FetchGroupsAction=新建FetchGroupsAction();
execute(操作,新的AsyncCallbackImpl(){
@凌驾
成功时公共无效(FetchGroupsResult结果){
groupList=result.getGroupDtos();
fireEvent(新的GroupListUpdateEvent(groupList));
}
});
}
因此,我在构造函数中调用fetchGroups以尽早获取它。因为它是一个AynchCallback,所以我“在某个时间”返回结果。然后,我尝试使用GroupListUpdateEvent将值传递给子编辑器。在其中,我声明了一个编辑器,如下所示:
public class GroupListEditor extends Composite implements
IsEditor<ListEditor<String, GroupItemEditor>> {
private static StringListEditorUiBinder uiBinder = GWT
.create(StringListEditorUiBinder.class);
interface StringListEditorUiBinder extends
UiBinder<Widget, GroupListEditor> {
}
//Gives us access to the event bus.
@Inject private EventBus eventBus;
...
public GroupListEditor() {
initWidget(uiBinder.createAndBindUi(this));
eventBus.addHandler(GroupListUpdatedEvent.TYPE, new GroupListUpdatedEvent.GroupListUpdatedHandler() {
@Override
public void onGroupListUpdatedEvent(GroupListUpdatedEvent event) {
Log.debug("onContainerUpdatedEvent caught");
allGroups = event.getGroupList();
if(allGroups != null) {
for (GroupDTO g : allGroups) {
lbAllGroups.addItem(g.getName(), g.getId().toString());
}
lbAllGroups.setVisibleItemCount(5);
Log.debug("Item list = " + lbAllGroups.getItemCount());
} else {
Log.debug("GROUP LIST is Null!");
}
}
});
}
public类GroupListEditor扩展复合实现
编辑{
私有静态StringListEditorUiBinder=GWT
.create(StringListEditorUiBinder.class);
接口StringListEditorUiBinder扩展
UiBinder{
}
//允许我们访问事件总线。
@注入私有事件总线事件总线;
...
公共GroupListEditor(){
initWidget(uiBinder.createAndBindUi(this));
eventBus.addHandler(GroupListUpdateEvent.TYPE,新的GroupListUpdateEvent.GroupListUpdatedHandler(){
@凌驾
public void OnGroupListUpdateEvent(GroupListUpdateEvent事件){
调试(“OnContainerUpdateEvent已捕获”);
allGroups=event.getGroupList();
如果(所有组!=null){
对于(组到g:所有组){
lbAllGroups.addItem(g.getName(),g.getId().toString());
}
lbAllGroups.setVisibleItemCount(5);
调试(“项列表=“+lbAllGroups.getItemCount());
}否则{
调试(“组列表为空!”);
}
}
});
}
当我尝试注册处理程序时,我得到一个异常。因此我希望事件总线没有正确注入。我遗漏了什么,如果我不在演示者中,如何使用事件和事件总线?
而且:这是用“实用”数据填充编辑器的正确方法吗?我想编辑器应该与他们关心的数据直接相关。但是我如何处理这种补充数据呢
谢谢:)您是否在
ContainerEdit或AlogPresenterWidgetView
中为您的组列表编辑器使用@UiField
?
如果是这样的话,依赖项注入将不起作用,因为基本上是手动创建GroupListEditor
,这将导致EventBus
为空
我还将使用构造函数注入而不是字段注入
GroupListEditor:
@Inject
public GroupListEditor(EventBus eventBus) {
this.eventBus = eventBus;
}
ContainerEditorDialogPresenterWidgetView:
public class ContainerEditorDialogPresenterWidgetView {
@UiField(provided=true)
GroupListEditor groupListEditor;
@Inject
public ContainerEditorDialogPresenterWidgetView(GroupListEditor groupListEditor);
this.groupListEditor = groupListEditor;
initWidget();
}
}
或者,您也可以通过ginject
直接获取您的GroupListEditor
实例。因此,您需要将GroupListEditor注入视图中,以使eventBus注入正常工作。这就是我错过的。再次感谢您的帮助:)
public class ContainerEditorDialogPresenterWidgetView {
@UiField(provided=true)
GroupListEditor groupListEditor;
@Inject
public ContainerEditorDialogPresenterWidgetView(GroupListEditor groupListEditor);
this.groupListEditor = groupListEditor;
initWidget();
}
}