Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top