|
GWTP Dispatch client 0.6-redhat-2 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A
- The type of the action extending Action
.R
- The type of the result extending Result
.public interface ClientActionHandler<A extends Action<R>,R extends Result>
Instances of this interface will handle specific types of Action
classes on the client.
ClientActionHandler
that
has been registered with the bound ClientActionHandlerRegistry
is
called and DispatchAsync
does
not automatically send the command over gwt-rpc to the server.
Client Action Handlers provide a number of flexible options:
ClientActionHandler
can take over and communicate directly
with the server, possibly using a different mechanism than gwt-rpc.
// Interface of cache singleton
public interface Cache {
<A extends Action<R>, R extends Result> R get(A action);
<A extends Action<R>, R extends Result> void put(A action, R result);
}
// Client action handler that injects the cache
public class RetrieveFooClientActionHandler
extends
AbstractCachingClientActionHandler<RetrieveFooAction, RetrieveFooResult> {
@Inject
RetrieveFooClientActionHandler(
Cache cache) {
super(RetrieveFooAction.class, cache);
}
}
// abstract client action handler that:
// - first checks cache and returns result immediately if found in cache
// - executes command on server using gwt-rpc
// - saves result to cache before returning it
public abstract class AbstractCachingClientActionHandler<A extends Action<R>, R extends Result>
extends AbstractClientActionHandler<A, R> {
private final Cache cache;
public AbstractCachingClientActionHandler(
Class<A> actionType, Cache cache) {
super(actionType);
this.cache = cache;
}
@Override
public DispatchRequest execute(final A action, final AsyncCallback<R> resultCallback,
ExecuteCommand<A, R> executeCommand) {
R cacheResult = cache.get(action);
if (cacheResult != null) {
resultCallback.onSuccess(cacheResult);
return new CompletedDispatchRequest();
} else {
return executeCommand.execute(action, new AsyncCallback<R>() {
@Override
public void onSuccess(R result) {
if(!request.isCancelled()) {
cache.put(action, result);
resultCallback.onSuccess(result);
}
}
@Override
public void onFailure(Throwable caught) {
resultCallback.onFailure(caught);
}
});
}
}
@Override
public DispatchRequest undo(A action, R result, AsyncCallback<Void> callback,
ClientDispatchRequest request, UndoCommand<A, R> undoCommand) {
// do nothing
return new CompletedDispatchRequest();
}
}
Method Summary | |
---|---|
DispatchRequest |
execute(A action,
com.google.gwt.user.client.rpc.AsyncCallback<R> resultCallback,
ExecuteCommand<A,R> executeCommand)
Handles the specified action. |
Class<A> |
getActionType()
|
DispatchRequest |
undo(A action,
R result,
com.google.gwt.user.client.rpc.AsyncCallback<Void> callback,
UndoCommand<A,R> undoCommand)
Undoes the specified action. |
Method Detail |
---|
DispatchRequest execute(A action, com.google.gwt.user.client.rpc.AsyncCallback<R> resultCallback, ExecuteCommand<A,R> executeCommand)
DelegatingDispatchRequest#isCancelled()
against the request
parameter.
action
- The Action
to execute.resultCallback
- The callback to use to communicate the result of the
action. Unless the request is cancelled, you must invoke
AsyncCallback.onSuccess(T)
on this callback once you have
obtained the result. If any failure occurs call
AsyncCallback.onFailure(java.lang.Throwable)
.executeCommand
- Call ExecuteCommand.execute(Action, com.google.gwt.user.client.rpc.AsyncCallback)
on this object to send the action over to the server via gwt-rpc.
As a parameter you can pass resultCallback
or your custom
AsyncCallback
if you want to process the result.
DispatchRequest
object. Never return null
,
instead return a new CompletedDispatchRequest
if you executed, cancelled or ignored the action.Class<A> getActionType()
Action
supported by this handler.DispatchRequest undo(A action, R result, com.google.gwt.user.client.rpc.AsyncCallback<Void> callback, UndoCommand<A,R> undoCommand)
DelegatingDispatchRequest#isCancelled()
against the request
parameter.
action
- The Action
to undo.result
- The Result
to undo.callback
- The callback to use to indicate when the action has been
undone. Unless the request is cancelled, you must invoke
AsyncCallback.onSuccess(T)
on this callback when you have
successfully undone the action. If any failure occurs call
AsyncCallback.onFailure(java.lang.Throwable)
.undoCommand
- Call UndoCommand.undo(Action, Result, com.google.gwt.user.client.rpc.AsyncCallback)
on
this object to send the action over to the server via gwt-rpc. As
a parameter you can pass callback
or your custom
AsyncCallback
if you want to perform any processing
following the undo.
DispatchRequest
object. Never return null
,
instead return a new CompletedDispatchRequest
if you executed, cancelled or ignored the action.
|
GWTP Dispatch client 0.6-redhat-2 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |