【发布时间】:2014-02-10 20:13:03
【问题描述】:
我没有创建一百个不同的 GWT-RPC 服务和 serviceAsync 类,而是尝试使用泛型创建一个服务。界面如下:
@RemoteServiceRelativePath("dispatch")
public interface CommandService extends RemoteService
{
public <T> Result<T> execute(Command command, T target);
}
这里Command 是我可以发出的所有不同命令的枚举,例如Login, Register, ChangePassword'等。在服务器端,我有一个Command 的HashMap 作为键,并且Executor 类作为值。对于每个Command,我都有一个对应的Executor。那个Executor被执行了,它的返回值在服务器端返回。
当我尝试在客户端上创建CommandServiceAsync 并尝试执行它时,就会出现问题。这是我的代码:
public enum Command
{
LOGIN,
REGISTER,
CHANGE_PW;
public <T> void execute(T target, final ResultReceiver<T> receiver)
{
CommandServiceAsync command = GWT.create(CommandService.class );
command.execute(this, target, new AsyncCallback<Result<T> >()
{
@Override
public void onFailure(Throwable caught)
{
MyProgram.handleFailure(caught);
}
@Override
public void onSuccess(Result<T> result)
{
receiver.receive( result );;
}
});
}
}
这里,Command.execute 是实际调用服务的方法。下面是我如何调用它来执行LOGIN 命令:
LoginForm form = new LoginForm();
Command.LOGIN.execute(form, new ResultReceiver<LoginForm>()
{
@Override
public void receive(Result<LoginForm> result)
{
Console.debug("Received result");
//result.getTarget() will return an instance of LoginForm
Console.debug("user: " + result.getTarget().getUser() );
Console.debug("pw: " + result.getTarget().getUser() );
}
});
问题出现在Command.execute 中的以下行:
CommandServiceAsync command = GWT.create(CommandService.class );
在这里,我收到以下错误:
错误:“com.xxx.CommandService”的延迟绑定失败;预计 随后的失败
错误:未捕获的异常已转义 com.google.gwt.event.shared.UmbrellaException:捕获异常: 'com.xxx.CommandService' 的延迟绑定失败(你忘了 继承一个必需的模块?)
原因: com.google.gwt.core.ext.UnableToCompleteException:(见上一个日志 条目)
我怎样才能完成我想做的事情?
【问题讨论】: