Instead of creating hundreds of different classes of GWT-RPC and Async services, I am trying to create a single service using generics. Here's the interface:
@RemoteServiceRelativePath("dispatch")
public interface CommandService extends RemoteService
{
public <T> Result<T> execute(Command command, T target);
}
Here Commandis an enumeration of all the various commands that I can issue, for example Login, Register, ChangePassword', etc. On the server side, I have HashMapof Commandas the key, and a Executoras the value. For each Command, I have a corresponding one Executor. Running Executor, and its return value is returned on the server side.
The problem occurs when I try to create CommandServiceAsyncon the client and try to execute it. Here is my code for this:
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");
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: (. )
, ?