Hello,
  MVP or MVC may help you to solve this issue.

  Here is some MVP solution that I'm using in one of my projects.
 
  public interface CityDao {
    void getAllCities(ApplicationCallback<List<City>> cities);
  }

  // may be tested without GWTTestCase
  public class CityDaoRpc implements CityDao {
    private MyCityServiceAsync  service;
    public CityDaoRpc(MyCityServiceAsync service) {
         this.service = service;
    }
   
    public void getAllCities(ApplicationCallback<List<City>> cities) {
         service.getAllCities(new AsyncCallback<List<City>> result) {
                // dispatch onSuccess and onFailure
         }
    }
  }

  public interface CityListView{
       void setSities(List<City> cities);
  }

  public class CityListViewWidget extends Composite implements CityListView{
          public CityListViewWidget (CityDao dao) {
               CitiesListPresenter presenter = new 
CitiesListPresenter(new CityListModel(), this, dao);
            
              
                // all user actions are redirected to the presenter 
which may update the database and the model if it's necessary
                presenter.onRowClicked(rowClicked)
         }
  }

  public class CityListModel{
      private List<City> cities;
      get/setters

       public void rowChanged(int row) {
           //fire event to the coordinator or to the presenter
       }
  }

public class CitiesListPresenter {
   public CitiesListPresenter (CityListModel model, CityListView, 
CityDao dao) {
      model.addCitiesUpdateHandler(new CityUpdateHandler<List<City>>() 
{         
           void onCitiesUpdated(List<City> cities) {
               updateCitiesView(cities);
           }
      }
      dao.getAllCities(new ApplicationCallBack<List<City>>() {
            @Override
            void onSuccess(List<City> result) {
                 model.setCities(result);
            }

            void onFail(Throwable t) {
                // handle some kind of error or create an abstraction of 
application class
            }
       }
     
  }
 
   public void onRowClicked(int row) {
        model.setClickedRow(row);
   }

  private void updateCities(List<City> city) {
       view.setCities(city);
  }
 
}

Advantages
1. Separation of business logic from the view
2. Easy testing with jmock ( also the async callbacks - 
http://www.jmock.org/gwt.html) without using of GWTTestCase
3. Code is low coupled and allows better reusing
4. Definition of a custom client side dao allows using of GWT-RPC, XML, 
JSON at the same time or using of different implementation
5. Most of the code is testable without hosted mode browser, i.e. tests 
are running fast
6. Views may communicate each other via custom business events - 
CityChangeSelectionEvent and etc.

Disadvantages
1. Code gets bigger in size
2. Widgets are not tested. For this you are free to use GWTTestCase or 
selenium. Both of them may help
3. Much more efforts for creation of unit tests
4. Much more classes. Much more module and etc, but it depends from the 
size of your project.

Hope this will help you in some way.

btw: If anyone has some suggestions about the design of the code, please 
let me know.

Regards,
  Miroslav
Neo wrote:
> Hi,
> I am working on a database driven GWT application. Now, in my client
> side I make RPC calls to basically fetch information from the
> databse.
> But the problem is that my client side code gets cluttered with RPC
> calls and onFailure methods and onSuccess methods. Along with this my
> UI code is also getting mixed up.
>
> How can avoid this problem ?
>
> I would like to put all my RPC calling logic in some sort of a
> delegate class and let the delegate class return the values to my
> Client class. But I doubt if that will work out as the return type of
> the onSuccess method is void :(
>
> To summerize, this is what I would like to have :
> Client (Design Layout, Call delegate method) ---------------->
> Delegate (make RPC calls, return value to Client) ------------->
> Server (Implement DAO logic, return value to delegate)
>
> Is it possible to achieve this sort of a design with GWT apps ?
>
>
> Could you please suggest a suitable design pattern for GWT
> applications so that the application can be maintained with ease in
> future?
>
> >
>   


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to