How to use BatchAction ?

77 views
Skip to first unread message

Justin Coutarel

unread,
Sep 18, 2013, 2:48:06 PM9/18/13
to gwt-pl...@googlegroups.com
Good morning all,

I’m trying to use BatchAction to fetch differents objects from my server within one single server call.
I’ve write the following code:

Action<BatchResult> batchAction = new BatchAction(OnException.CONTINUE, new ActionA(), new ActionB()) {

           
@Override
           
public String getServiceName() {
               
return DEFAULT_SERVICE_NAME;
           
}

           
@Override
           
public boolean isSecured() {
               
return false;
           
}
           
 
};

dispatchAsync
.execute(batchAction, new AsyncCallback<BatchResult>() {

           
@Override
           
public void onFailure(Throwable caught) {
               
Window.alert("Error: " + caught.getMessage());
           
}
       
           
@Override
           
public void onSuccess(BatchResult result) {
               
Window.alert("Successfull !");
 
 
});
 
Obviously, ActionA and ActionB are actions and if I execute this actions separately, they work. The callback onFailure method is called without make a server call with a null caught parameter.

Could you tell me why my code doesn’t work or give me a working example ?

Thank you very much

P.S.: Sorry for my bad English, I'm french.

 


Message has been deleted

Justin Coutarel

unread,
Sep 19, 2013, 4:29:33 AM9/19/13
to gwt-pl...@googlegroups.com
I understood the problem. I used an anonymous class, but GWT cannot serialize it and it throw an exception without message (null) and then onFailure is called with null message.
So, I created a class that extends the BatchAction class but GWTP throw an exception because there is no handler registered for handle this action.
Thus, I created a facade class that creates an BatchActionHandler and calls the execute method. I bound this class to the my batch action with the bindHandler method.

The BatchAction class:

public class MyBatchAction extends BatchAction {


   
MyBatchAction() {
       
super(OnException.CONTINUE, new ActionA(), new ActionB());

   
}


   
@Override
   
public String getServiceName() {
       
return DEFAULT_SERVICE_NAME;
   
}


   
@Override
   
public boolean isSecured() {
       
return false;
   
}
}



The BatchActionHandler class:

public class MyBatchActionHandler implements ActionHandler<MyBatchAction, BatchResult> {
   
   
BatchActionHandler handler = new BatchActionHandler();


   
@Override
   
public BatchResult execute(MyBatchAction action, ExecutionContext context) throws ActionException {
       
return handler.execute(action, context);
   
}


   
@Override
   
public Class<MyBatchAction> getActionType() {
       
return MyBatchAction.class;
   
}


   
@Override
   
public void undo(MyBatchAction action, BatchResult result, ExecutionContext context) throws ActionException {
        handler
.undo(action, result, context);
   
}
}


And My ServerModule class:

public class ServerModule extends HandlerModule {


   
@Override
   
protected void configureHandlers() {


        bindHandler
(ActionA.class, ActionAHandler.class);


        bindHandler
(ActionB.class, ActionBHandler.class);
       
        bindHandler
(MyBatchAction.class, MyBatchActionHandler.class);
   
}
}


My problem is solved. If anyone have a better solution, he can suggest me :-)

P.S.: Again, sorry for my bad English, I'm french

Christopher Viel

unread,
Oct 1, 2013, 12:24:05 PM10/1/13
to gwt-pl...@googlegroups.com
Good to know. I'm curious if this one would work without the hassle of a facade though:

public class ServerModule extends HandlerModule {
  @Override
  protected void configureHandlers() {
    bindHandler(ActionA.class, ActionAHandler.class);
    bindHandler(ActionB.class, ActionBHandler.class);
    bindHandler(BatchAction.class, BatchActionHandler.class);
  }
}

--
You received this message because you are subscribed to the Google Groups "GWTP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gwt-platform...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages