Question

On the code below I am injecting a PlaceManager on the 4th line, and trying to use the placeManager.revealPlace() on the last line. However, at that moment I get a null exception.

Furthermore, if I add a if(placeManager==null){ Window.alert("Hello"); } before that line, the alert is displayed.

Any ideas why is this happening? Perhaps because it is executed inside a FieldUpdater handler?

THANKS

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);
              }
        });
}
Was it helpful?

Solution

Did you bind(...) your PlaceManager to an implementation in your ClientModule (and can we see the latter?)

Have you checked and verified your GinModules/Ginjector (assuming you're using gin)?

Cheers,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top