Search code examples
gwtgwt-platform

Dealing with model save and update with GWT Platform


I'm trying to adapt my GWT web application from my home-grown MVC to GWT Platform.

I've managed to port the my application views with presenters, and essentially able to access views via PlaceRequest. And with changing the URL (#).

However I am not sure how to deal with Models using this GWT platform, in the common MVP I know there is a go() method in the presenter which fetches data, say from server via RPC.

In the GWT platform presenter here are the methods automatically generated by the Eclipse plugin:

  • Constructor
  • revealInParent
  • onBind
  • onReset

Where should I put the RPC code that will fetch and update my model. Say in the presenter I have:

ProfilePresenter.java:

public class ProfilePresenter
        extends
        Presenter<ProfilePresenter.MyView, ProfilePresenter.MyProxy> {

    public interface MyView extends View {
        HasText getFullname();
        HasText getLocation();
        HasText getAboutme();
        HasText getLastlogin();
    }

    private User user; // Model which represents the User information etc.

And when the View associated with the Presenter is shown I need to fetch the User model from the server and update the model and then subsequently update the view through the interfaces it expose.

Also, say I have some buttons in the view, which then can be accessed by the presenter through HasClickHandler where should I put the event handlers?


Solution

  • Sydney covered most of your questions.

    In general onResetmethod is a good place to make backend calls.
    Sometimes when the backend call takes longer and you want to display the view only after the data was loaded you can use manual reveal.
    But for the profile page I don't think that is necessary.

    I also agree with the reverse MVP pattern. It's way easer to test presenters using the reverse MVP Pattern than using the HasXXXHandlers interfaces.