在 GWT 异步回调中,如何在 onSuccess 中处理相同的 return 类型?
In a GWT asynchronous callback, how can I handle the same return types in onSuccess?
如果我在服务中有两个 boolean
方法,我如何确保 onSuccess
方法处理返回 boolean
的正确方法?
例如,在onSuccess
方法中我说:
if (result instanceof Boolean) {};
有什么方法可以区分返回布尔值的服务方法吗?否则无法保证正确的代码将在我的 onSuccess 方法中执行,就好像结果是 boolean
如果我的两个 boolean
服务方法中的任何一个被调用它就会执行。
这是我面临的问题的示例:
private class DefaultCallback implements AsyncCallback
{
@Override
public void onFailure(Throwable caught)
{
mainGUI.getServerResponseLabel().setStyleName("serverResponseLabelError");
mainGUI.getServerResponseLabel().setHTML("An error occurred while "
+ "attempting to contact the server. Please check your network " + "connection and try again.");
}
@Override
public void onSuccess(Object result)
{
if (result instanceof Boolean)
{
//
I have two methods that return a boolean here,
so this block will execute no matter which one is called;
for one method I want to display a GUI windows saying "Upload complete",
and for another, create an excel spreadsheet. But the boolean value of one method won't be relevant to the other
有很多灰色区域,但请耐心等待:
在 SomethingRPCService.java
boolean isA();
boolean isB();
在SomethingRPCServiceAsync.java
void isA(AsyncCallback<Boolean> callback);
void isB(AsyncCallback<Boolean> callback);
在你的 activity
somethingService.isA(new AsyncCallback<Boolean>() {
@Override
public void onSuccessImpl(final Boolean response) {
//will be executed on success of THIS call
}
@Override
public void onFailure(final Throwable caught) {
// not relevant here
}
});
somethingService.isB(new AsyncCallback<Boolean>() {
@Override
public void onSuccessImpl(final Boolean response) {
//will be executed on success of THIS call
}
@Override
public void onFailure(final Throwable caught) {
// not relevant here
}
});
您可以(必须?)实际输入您的 return
编辑:通过你的例子,我可以看得更清楚一些;你的回调不应该相同,你应该重写它所以代码不一样,因为它不是
如果我在服务中有两个 boolean
方法,我如何确保 onSuccess
方法处理返回 boolean
的正确方法?
例如,在onSuccess
方法中我说:
if (result instanceof Boolean) {};
有什么方法可以区分返回布尔值的服务方法吗?否则无法保证正确的代码将在我的 onSuccess 方法中执行,就好像结果是 boolean
如果我的两个 boolean
服务方法中的任何一个被调用它就会执行。
这是我面临的问题的示例:
private class DefaultCallback implements AsyncCallback
{
@Override
public void onFailure(Throwable caught)
{
mainGUI.getServerResponseLabel().setStyleName("serverResponseLabelError");
mainGUI.getServerResponseLabel().setHTML("An error occurred while "
+ "attempting to contact the server. Please check your network " + "connection and try again.");
}
@Override
public void onSuccess(Object result)
{
if (result instanceof Boolean)
{
//
I have two methods that return a boolean here,
so this block will execute no matter which one is called;
for one method I want to display a GUI windows saying "Upload complete",
and for another, create an excel spreadsheet. But the boolean value of one method won't be relevant to the other
有很多灰色区域,但请耐心等待: 在 SomethingRPCService.java
boolean isA();
boolean isB();
在SomethingRPCServiceAsync.java
void isA(AsyncCallback<Boolean> callback);
void isB(AsyncCallback<Boolean> callback);
在你的 activity
somethingService.isA(new AsyncCallback<Boolean>() {
@Override
public void onSuccessImpl(final Boolean response) {
//will be executed on success of THIS call
}
@Override
public void onFailure(final Throwable caught) {
// not relevant here
}
});
somethingService.isB(new AsyncCallback<Boolean>() {
@Override
public void onSuccessImpl(final Boolean response) {
//will be executed on success of THIS call
}
@Override
public void onFailure(final Throwable caught) {
// not relevant here
}
});
您可以(必须?)实际输入您的 return
编辑:通过你的例子,我可以看得更清楚一些;你的回调不应该相同,你应该重写它所以代码不一样,因为它不是