Search code examples
gwtgwt-mvp

Best practice - data submission GWT MVP


I'm looking for some best practices for form submission in GWT with MVP.

In my application a Dialog box is opened where a simple from is rendered. When the 'Ok' button is clicked, element values are read and assigned to a value object. This object is then added to a new Place.

View:

   onOkButtonClicked(event){
       // read values from dialog box elements
       // assign the values to ValueObject(name, number, address)
       presenter.goto(new ListRecordPlace("list","addrecord", valueObject);
    }

Activity:

ListRecordActivity(ListRecordPlace place, eventBus){
   this.place = place;
}

start(...){
   if(this.place.getAction().equals("addrecord")){
      // RPC call to add the new record: this.place.getNewRecord();
      // RPC returns list of records
      view.setRecordList();
      container.setWidget(view.asWidget());
   }
}

Is this the right way to submit data to server with MVP Activities and Places?


Solution

  • As you are using MVP, the call of the RPC service should be done in the presenter.

    OK click in view -> view: call presenter (presenter.okClicked()) - > presenter: update values and call RPC service to save -> presenter: after successful save go to other place.

    When you go to the next place, you should not transfer the data using the Place object. Objects responsible for handling the new place should take care of the data update and display.