本文介绍了如何取消选择GWT CellTable中的一行而不触发SelectionChange(...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个启用了SingleSelectionModel的GWT CellTable。一旦用户点击了一行,onSelectionChange(...)会弹出我的确认对话框,询问用户是否继续。问题是当用户点击取消时,没有任何反应,但他无法选择相同的行(假设CellTable中只有一行)。我知道一旦用户点击取消,我可以清除选择,但那会再次触发SelectionChange(..)并触发我的Confirmation对话框......这是一个无限循环。



以下是我的代码:

  // //将SelectionModel添加到dTable; 
final SingleSelectionModel< Driver> ssm = new SingleSelectionModel< Driver>();
dTable.setSelectionModel(ssm);
ssm.addSelectionChangeHandler(new SelectionChangeEvent.Handler(){
@ Override
public void onSelectionChange(final SelectionChangeEvent event)
{

SC.confirm 你想联系驱动程序吗?,new BooleanCallback(){
public void execute(Boolean value){
if(value!= null&& value){
final驱动程序d = ssm.getSelectedObject();
dataStoreService.updateDrivers(d._UUID.toString(),tripDate.getValue(),loginInfo.getEmailAddress(),destination.getText()。trim(),
新的AsyncCallback< String>(){
public void onFailure(可捕获的Throwable){

caught.printStackTrace();
}

public void onSuccess(String uuid){
Window.alert(驱动程序已通知,请保留您的参考ID:+ uuid);
}
});
dataStoreService。 getBookings(loginInfo.getEmailAddress(),new AsyncCallback< List< Booking>>(){
public void onFailure(Throwable caught){

caught.printStackTrace();
}

public void onSuccess(List< Booking> myBookings){
ClientUtilities.populateBookings(bookingDataProvider,myBookings);
}
});
} else {
//清除选择
//ssm.setSelected(ssm.getSelectedObject(),false);

}
}
});

}
});

有人能告诉我如何处理CellTable中的这种情况吗?

解决方案

SelectionChangeEvent 已被解雇之后选择已更改。这不是要求确认的合适地点:已经太晚了。您最好使用 CellPreviewEvent.Handler 。请参阅,讨论完全相同的问题(确认选择更改)并提供示例代码。


I have a GWT CellTable with SingleSelectionModel enabled. Once a user clicks a row, the onSelectionChange(...) fires up my Confirmation Dialog which asks the user whether to proceed or not. The issue is when the user clicks 'Cancel', nothing happens but he is not able to select the same row (assume only 1 row in the CellTable) I know I can clear the selection once the user clicks 'Cancel', but that will fires onSelectionChange(..) again and triggers my Confirmation Dialog ..... it's an infinite loop.

The following is my code:

// Add SelectionModel to dTable;
final SingleSelectionModel<Driver> ssm = new SingleSelectionModel<Driver>();
dTable.setSelectionModel(ssm);
ssm.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@ Override
public void onSelectionChange(final SelectionChangeEvent event)
{

SC.confirm("Do you want to contact the driver?", new BooleanCallback() {
public void execute(Boolean value) {
if (value != null && value) {
final Driver d = ssm.getSelectedObject();
dataStoreService.updateDrivers(d._UUID.toString(),tripDate.getValue(), loginInfo.getEmailAddress(),destination.getText().trim(),
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {

caught.printStackTrace();
}

public void onSuccess(String uuid) {
Window.alert("The driver has been notified. Please keep your reference id: "+uuid);
}
});
dataStoreService.getBookings(loginInfo.getEmailAddress(), new AsyncCallback<List<Booking>>() {
public void onFailure(Throwable caught) {

caught.printStackTrace();
}

public void onSuccess(List<Booking> myBookings) {
ClientUtilities.populateBookings(bookingDataProvider, myBookings);
}
});
} else {
//clear selection
//ssm.setSelected(ssm.getSelectedObject(), false);

}
}
});

}
});

Can someone tell me how to handle this kind of situation in CellTable? I'm open for any solutions.

解决方案

The SelectionChangeEvent is fired after the selection has changed. This is not the appropriate place to ask for confirmation: it's too late.

You'd better use a CellPreviewEvent.Handler. See https://groups.google.com/d/topic/google-web-toolkit/YMbGbejU9yg/discussion which discusses the exact same issue (confirm selection change) and provides sample code.

这篇关于如何取消选择GWT CellTable中的一行而不触发SelectionChange(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 23:14