GWT:Injected PlaceManager为空

时间:2012-10-22 12:28:33

标签: gwt requestfactory inject gwt-celltable event-bus

在下面的代码中,我在第4行注入PlaceManager,并尝试在最后一行使用placeManager.revealPlace()。但是,那一刻我得到一个空例外。

此外,如果我在该行之前添加if(placeManager==null){ Window.alert("Hello"); },则会显示警告。

任何想法为什么会发生这种情况?也许是因为它是在FieldUpdater处理程序中执行的?

感谢

public class CellTableManager {

private final DialectiveRequestFactory requestFactory = GWT.create(DialectiveRequestFactory.class);
private EventBus eventBus;
@Inject PlaceManager placeManager;

public CellTableManager (final CellTable<Diagram> cellTable, SimplePager pager) {
    DiagramDatabase.get().getDiagramProvider().addDataDisplay(cellTable);
    ListHandler<Diagram> sortHandler = new ListHandler<Diagram>(
        DiagramDatabase.get().getDiagramProvider().getList());
    cellTable.addColumnSortHandler(sortHandler);
    this.eventBus = new SimpleEventBus();
    requestFactory.initialize(eventBus);
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
    pager.setDisplay(cellTable);

    final SelectionModel<Diagram> selectionModel = initSelectionMode(cellTable);

    initTableColumns(cellTable, selectionModel, sortHandler);

    DiagramRequest diagramRequest = requestFactory.diagramRequest();
    diagramRequest.listAll().fire(new Receiver<List<DiagramProxy>>() {
        public void onSuccess(List<DiagramProxy> response) {
            for (int i=0;i<response.size();i++) {
                insertEmptyRow(cellTable, response.get(i));
            }
        }
    });
}

private void initTableColumns(final CellTable<Diagram> cellTable,
            final SelectionModel<Diagram> selectionModel, ListHandler<Diagram> sortHandler) {
        Column<Diagram, String> titleColumn = new Column<Diagram, String>(
            new TextCell()) {
          @Override
          public String getValue(Diagram object) {
            return object.getTitle();
          }
        };
        titleColumn.setSortable(true);
        sortHandler.setComparator(titleColumn, new Comparator<Diagram>() {
            @Override
            public int compare(Diagram o1, Diagram o2) {
                return o1.getTitle().compareTo(o2.getTitle());
            }
        });

        cellTable.addColumn(titleColumn, BasicConstants.editTableText[0]);
        cellTable.setColumnWidth(titleColumn, 20, Unit.PCT);

        Column<Diagram, String> descriptionColumn = new Column<Diagram, String>(
            new TextCell()) {
          @Override
          public String getValue(Diagram object) {
            return object.getDescription();
          }
        };

        descriptionColumn.setSortable(true);
        sortHandler.setComparator(descriptionColumn, new Comparator<Diagram>() {
            @Override
            public int compare(Diagram o1, Diagram o2) {
                return o1.getDescription().compareTo(o2.getDescription());
            }
        });

        cellTable.addColumn(descriptionColumn, BasicConstants.editTableText[1], "");
        cellTable.setColumnWidth(descriptionColumn, 50, Unit.PCT);

        Column<Diagram, String> editColumn = new Column<Diagram, String>(
                new ButtonCell()) {
              @Override
              public String getValue(Diagram object) {
                return "edit";
              }
            };

        cellTable.addColumn(editColumn, "");
        editColumn.setFieldUpdater(new FieldUpdater<Diagram, String>() {
              @Override
              public void update(int index, Diagram object, String value) {
                  String diagramCode = object.getDiagramId(); 
                  ClientState.setCurrentDiagramId(diagramCode);
                  PlaceRequest request = new PlaceRequest(NameTokens.e).with("id", diagramCode);
                  placeManager.revealPlace(request);
              }
        });
}

1 个答案:

答案 0 :(得分:2)

bind(...) PlaceManager ClientModuleGinModules中的Ginjector(我们可以看到后者吗?)

您是否已检查并验证了gin / {{1}}(假设您使用的是{{1}})?

干杯,