我在EventBus的一个真正的SimpleEventBus实现上有一些问题:我有一个活动,它也是特定事件的处理程序.此事件由服务触发.
代码:
@Mock private AssetCellList view;
@Mock private AcceptsOneWidget panel;
@Mock private SelectionModel<Asset> selectionModel;
@Mock private HasData<Asset> cellList;
@Mock private AssetService service;
@Mock private Asset asset;
@Mock private List<Asset> list;
@Mock private AssetListDTOClientImpl assetDTO;
@Mock private AssetEvent event;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Test
public void test(){
/*Some stubbing*/
when(view.getSelectionModel()).thenReturn(selectionModel);
when(view.getList()).thenReturn(cellList);
when(assetDTO.getAssetList()).thenReturn(list);
when(assetDTO.getAssetList().get(anyInt())).thenReturn(asset);
when(event.getAssetDTO()).thenReturn(assetDTO);
/*Creatin the Real EventBus*/
EventBus eventBus = new SimpleEventBus();
/*Creating the activity */
AssetListActivity activity = new AssetListActivity(eventBus,
view,
service);
/*Spying the …Run Code Online (Sandbox Code Playgroud) 我正在努力加快使用GWT活动和地点.我正在测试最初在这篇好博客文章中找到的一些源代码.
我发现在bind()期间添加的处理程序似乎永远不会删除.我对Activity javadoc的一点了解让我觉得它们应该在调用Activity的onStop()方法时自动删除.
在调用此方法之前,它已注册的所有事件处理程序都将被删除.
但每次单击一个按钮时,相应的处理程序称为n + 1次.
我错过了什么?如果有更多我可以提供的信息,请告诉我.
以下是代码中的相关代码段:
public class ContactsActivity extends AbstractActivity {
private List<ContactDetails> contactDetails;
private final ContactsServiceAsync rpcService;
private final EventBus eventBus;
private final IContactsViewDisplay display;
private PlaceController placeController;
public interface IContactsViewDisplay {
HasClickHandlers getAddButton();
HasClickHandlers getDeleteButton();
HasClickHandlers getList();
void setData(List<String> data);
int getClickedRow(ClickEvent event);
List<Integer> getSelectedRows();
Widget asWidget();
}
public ContactsActivity(ClientFactory factory) {
GWT.log("ContactActivity: constructor");
this.rpcService = factory.getContactServiceRPC();
this.eventBus = factory.getEventBus();
this.display = factory.getContactsView();
this.placeController = factory.getPlaceController();
}
@Override
public void …Run Code Online (Sandbox Code Playgroud) 我正在使用GWT 2.4和MVP模式,所以我有Presenters和Views(没有UIBinder).我有其中一个问题.我有一个带有TabLayoutPanel的视图,里面有更多的小部件.如果我使用LayoutPanel一切正常,但如果我使用RootLayoutPanel我有错误.
public class JaviView extends Composite implements FacturasPresenter.Display {
private RootLayoutPanel rootLayoutPanel = RootLayoutPanel.get();
private TabLayoutPanel tabPanel;
//...more declarations
}
public JaviView(){
initWidget(rootLayoutPanel);
rootLayoutPanel.setSize("100%", "100%");
//...
tabPanel = new TabLayoutPanel(1.7, Unit.EM);
//add widgets to tabPanel
tabPanel.setWidth("100%");
rootLayoutPanel.add(tabPanel);
}
Run Code Online (Sandbox Code Playgroud)
我得到:这个小部件的父级没有实现HasWidgets.
Caused by: java.lang.IllegalStateException: This widget's parent does not implement HasWidgets
at com.google.gwt.user.client.ui.Widget.removeFromParent(Widget.java:204)
at com.google.gwt.user.client.ui.Composite.initWidget(Composite.java:145)
at contabilidad.presentation.client.view.facturas.JaviView.<init>(JaviView.java:318)
Run Code Online (Sandbox Code Playgroud)
第318行是:initWidget(rootLayoutPanel).如果我使用LayoutPanel我没有那个错误,但我需要使用RootLayoutPanel.
我已经复制了代码并粘贴到另一个View中,使用RootLayoutPanel并且工作正常,所以我不知道问题出在哪里.我一直在寻找解决方案几个小时.提前致谢.
全部跟踪:
10:16:49.595 [ERROR] [contabilidadweb] Uncaught exception escaped
com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129) …Run Code Online (Sandbox Code Playgroud) 我有一个MVP应用程序实现.后退按钮工作正常.我想以编程方式返回上一个地方.我该怎么办?
我正在寻找类似的东西:
clientFactory.getPlaceController().goBack();
Run Code Online (Sandbox Code Playgroud)
谢谢.
gwt ×5
gwt-mvp ×5
composite ×1
gwt-history ×1
gwt2 ×1
java ×1
mockito ×1
mvp ×1
tablelayout ×1
unit-testing ×1