java - GXT 3 : GridSelectionModel SelectionEvent/SelectionChangedEvent not firing

标签 java gwt event-handling grid gxt

GXT 3 问题:

有谁知道为什么当我选择网格上的任何行时这两个处理程序不会被触发? SelectionModel为GridSelectionModel,设置为单选。

还有什么需要做的声明吗?就这么简单,不是吗。我为 GXT 2.2 添加事件监听器没有问题,但 GXT 3 中有一些更改。这些事件用于检测行选择,不是吗?

SelectionChangedHandler<Summary> gridSelectionChangedHandler = 
  new SelectionChangedHandler<Summary>() {
    public void onSelectionChanged(
      SelectionChangedEvent<Summary> event) {
        Summary rec = event.getSelection().get(0);
        Window.alert("Row = "+ rec.getId());    
    }
  };

SelectionHandler<Summary> gridSelectionHandler =
  new SelectionHandler<Summary>() {
    public void onSelection(SelectionEvent<Summary> event) {
      Summary rec = event.getSelectedItem();
      Window.alert("Row = "+ rec.getId());    
    }
  };

public SummaryViewImpl() {
  uiBinder.createAndBindUi(this);
  this.grid.addSelectionChangedHandler(gridSelectionChangedHandler);
  this.grid.addSelectionHandler(gridSelectionHandler);
}

但是,我对 RowClickEvent 没有任何问题,因为以下内容正在触发:

@UiHandler({ "grid" })
void onRowClick(RowClickEvent event){
    int row = event.getRowIndex();
    Window.alert("Row = "+ row);        
}

grid 是 SummaryGrid 的一个实例:

public class SummaryGrid
extends Grid<Summary>{


  {
    this.sm = new GridSelectionModel<Summary>();
    this.sm.setSelectionMode(SelectionMode.SINGLE);
  }


  blah ... blah ...

  public HandlerRegistration addSelectionChangedHandler(SelectionChangedHandler<Summary> handler){
    return this.getSelectionModel().addSelectionChangedHandler(handler);
  }

  public HandlerRegistration addSelectionHandler(SelectionHandler<Summary> handler){
    return this.getSelectionModel().addSelectionHandler(handler);
  }

  blah ... blah ...
}

最佳答案

试试这个grid.getSelectionModel().addSelectionChangedHandler

不确定您是否需要先设置选择模式,但我的工作代码如下:

grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

grid.getSelectionModel().addSelectionChangedHandler(new SelectionChangedHandler<Summary>() {
...
}

关于java - GXT 3 : GridSelectionModel SelectionEvent/SelectionChangedEvent not firing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15513785/

相关文章:

java - 删除链表偶数个节点并反向打印

java - SmartGWT - 动态更新ListGridRecord

c++ - Windows MessageBox 忽略 WM_CLOSE

javascript - 跨浏览器检测 JavaScript 中的 Flash "Click"事件

java - Java 单例应该使用静态变量吗?

java - 使用 SAS 从 Java 批量插入 Azure 表失败

java - 如何在多个 GWT eclipse 项目之间共享代码?

user-interface - 如何将 Id 添加到 GWT 屏幕上的小部件以进行测试

javascript - 在 Javascript 中处理 URL 片段标识符( anchor )更改事件

java - Hibernate用null更新子实体并且不删除,如何强制它?