MVP and the connection between GWT widgets

If I use the MVP template with GWT, like in GWT, the best practices say from Google I / O since 2009, but spread the information to several widgets, how should the value object be filled?

Say I have EditPersonView / Presenter, EditPetView / Presenter and EditAddressView / Presenter, and the last two are widgets as part of the panel in EditPersonView. With them, I have the following class:

class PersonDetails {
    private PetDetails pet;
    private AddressDetails addressDetails;

    // ...
}

PetDetails and AddressDetails instance variables are managed in their presentation colleagues. When a user clicks the Save button in EditPersonView, how should the widgets communicate so that PersonDetails is populated with information from child widgets?

+5
source share
3 answers

I ran into the same problem in several different GWT applications that I developed using the Ray Ryan approach. My preferred solution is to create a Singleton “session object” that saves the state of this part of the application. In your example, it might look like this:

interface EditPersonSession {

    void fetchPerson(PersonId id);
    PersonDetails getCurrentPersonDetails();
    void updatePersonDetail(PersonDetail<?> detail);
    void updatePetDetail(PetDetail<?> detail);
    void updateAddressDetail(AddressDetail<?> detail);
    void save();

}

All three speakers contain a reference to the session object (possibly entered by Gin). Whenever the user interface (view) is manipulated by the user, the host associated with this view immediately pushes the state to a shared session object. For example, inside EditAddressPresenter:

view.getStreetNameTextBox().addValueChangeHandler(new ValueChangeHandler() {

    void onValueChange(ValueChangeEvent<String> event) {
        editPersonSession.updateAddressDetail(new StreetNameAddressDetail(event.getValue()));
    }

}

, , . . , EditPersonPresenter:

view.getSaveButton().addClickHandler(new ClickHandler() {

    void onClick(ClickEvent event) {
        editPersonSession.save();
    }

}

, , . , , , ​​( , ), , ( Singleton HandlerManager). PersonDetails .

+1

. 42 Ray Ryan Google IO 2009, . " " ( HandlerManager) PetDetailsChangedEvent (. 45). , , .. , , - RR :)

+3

, , . , PetWidget Pet, PersonWidget Person. PersonWidget PetWidgets, , , , Person Pet.

0

All Articles