1

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?

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
Sree
  • 746
  • 6
  • 21
  • Please stop using the `google-places-api` tag for GWT Places, it's an enterily different thing! https://developers.google.com/maps/documentation/places/ – Thomas Broyer Apr 05 '12 at 08:58

2 Answers2

0

A Place is not an action, it's (as its name suggests) a location.

So no, it's the absolutely wrong way of doing things. You should do the RPC in response to the OK button being clicked and then only go to the ListRecordPlace where the record will be visible.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • This is my first attempt at GWT. So I'm very confused at this. Please can you give a code snippet for my simple form submission scenario? – Sree Apr 05 '12 at 16:21
  • Where should I read the form values - In the ActivityMapper or the Activity? Where should I do my RPC - In the ActivityMapper or Activity? Or do I need a Presenter. I thought Activity is is same as a presenter. Or may be I should define a method in the Presenter - say addRecord(parameters....). This method will do the RPC and then go ListRecordPlace. Please help me with this. – Sree Apr 05 '12 at 16:28
  • Yes, do that! (with the presenter being your activity) – Thomas Broyer Apr 05 '12 at 18:22
0

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.

Goran Nastov
  • 995
  • 1
  • 9
  • 17
  • Ok. I'm trying to understand this. GWT designer is creating a presenter with goto(Place place) method. If my View calls presenter.okClicked(); I assume this method need not take any argument. The okClicked() method will read View.getName(), view.getNumber() and view.getAddress(); and then call the RPC. And then clientFactory.getPlaceController.goto(new RecordListPlace()). Why's the presenter.goto has a Place arguement? Thanks agin for your valuable comments. – Sree Apr 05 '12 at 16:34
  • I'm trying to understand more - Activity.addRecord() will read values from the view and make the RPC to add a new record. Then goes to the RecordListPlace. The start(...) method in the Activity will be invoked, where it will make another RPC to get the list of records from server. If my previous addRecord() returned the updated list after adding, my second RPC is simply a waste. I guess I'm making sense here. – Sree Apr 05 '12 at 16:52
  • This is another issue, and the answer to that one is to use some caching, so that your list activity does not actually need to contact the server. – Thomas Broyer Apr 05 '12 at 18:25