Hi Gregor, I would like to thank you for replying to my query. I am trying my level best not to change DAO pattern which is already exists in my application. There were lot of methods returns ArrayList and Vectors for different purpose. According to your reply now I need to change my DO as well.
Would you please clarify one thing, if I use ArrayList or Vector instead a class (which implements Serilizable) as return type as you mentioned your reply for business methods then I am getting some warning like " Keys will not be Serilized because it is not final". Have to use always class as return type in GWT RPC business methids instead traditional java programming return ( ArrayList,Vector etc,,) ? Thanks Arul On Dec 17, 9:31 am, gregor <[email protected]> wrote: > Hi Arul, > > Yes and no. Yes. this is the way you set up RPC services client side, > but no, you do not necessarily have to have dozens of separate > callbacks, one for every single use case. > > For example, here you have two methods that both return vectors of > accounts. You can merge them into a single RPC service method (thereby > cutting out half the tedious callback code) using a variant of the > Command pattern. For example: > > public class AccountsCommand implements Serializable { > > enum Operation {available, selected, ....,etc}; > > private Operation op; // best made immutable > private Vector<Account> accounts = new Vector<Account>(); > > // constructors, getters, setters, etc > > } > > You set the op and dispatch one of these to a single RPC service and > the RPC service returns the same object that now contains the results > e.g. > > public interface AccountsService extends RemoteService { > AccountsCommand getAccounts(AccountsCommand command); > > } > > This is particularly convenient with enums because you can use a > switch statement in the (now) single callback to call the right > methods client side to control the UI, e,g, > > public void onSuccess(AccountsCommand command) { > Command.Operation operation = command.getOperation(); > switch (operation) { > case available: {doSomething(command.getAccounts > ());break;} > case selected: {doSomethingElse(command.getAccounts > ());break;} > //etc > } > "); > > which I think is quite neat and readable. You can also easily add > additional fields to AccountsCommand that might become necessary/ > desirable without altering the RPC infrastructure code at all, and > also any useful utility methods for manipulating lists of accounts > (sorting for example). I like this approach because I think it > maintains a strong business focus around a group of related use cases > at the same time as simplifying the tedious RPC infrastructure code. > > regards > gregor > > On Dec 17, 2:17 pm, Arul <[email protected]> wrote: > > > > > Hi, > > I written two business method inside service class. > > When I call these two methods inside client class, I have to write two > > seperate block containing onSuccess, onFailure methods for each of the > > business method in service class. > > > For Example see my service class below > > ------------------------------------------------------------------------------------------------------ > > public interface AccountsService extends RemoteService { > > Vector getAvailbleAccounts(); > > Vector getSelectedAccounts();} > > > ------------------------------------------------------------------------------------------------------ > > > Please find below my implementation (client) class for above two > > methods > > ----------------------------------------------------------------------------------------------------------------------------- > > AsyncCallback<Vector> callback = new AsyncCallback<Vector>() { > > public void onFailure(Throwable caught) { > > System.out.println("Inside getAvailbleAccounts Error "); > > > } > > > public void onSuccess(Vector result) { > > System.out.println("Inside getAvailbleAccounts On Success "); > > }; > > accountServiceSvc.getAvailbleAccounts(callback); > > > AsyncCallback<Vector> callback1 = new AsyncCallback<Vector>() { > > public void onFailure(Throwable caught) { > > System.out.println("Inside getSelectedAccounts Error "); > > } > > > public void onSuccess(Vector result) { > > System.out.println("Inside getSelectedAccounts On Success > > "); > > } > > }; > > accountServiceSvc.getSelectedAccounts(callback1); > > ----------------------------------------------------------------------------------------------------------------------------- > > > Is this the way of writting blocks for every business method in GWT > > RPC? > > > Thanks > > Arul- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
