Pass parameters between two presenter widgets efficiently with GWT-Platform

129 Views Asked by At

I have one presenter called as ParentPresenter and two presenterWidgets, ChildPresenter1 and ChildPresenter2.

ParentPresenter contains both ChildPresenter1, ChildPresenter2. ChildPresenter1 has more than 1000 random checkboxes and user can select/deselect any of them.

After user click on "Save" (which is placed in ChildPresenter2), ChildPresenter2 should get the list of select/deselect checkboxes value from ChildPresenter1. I am confused how ChildPresenter2 will receive the ChildPresenter1 data,

  1. Create a event which will be fired by ChildPresenter1 on each checkbox select/deselect and ChildPresenter2 register for that event and keep updated with data. But seeing 1000+ select/deselect possible on ChildPresenter1 is it a good solution?
  2. When ChildPresenter2 "Save" is pressed it fires an event, and ChildPresenter1 listens to it, prepare all the data and fire one more event from ChildPresenter1 with data, this event will be handled by ChildPresenter2 to get data. This sounds silly, isnt it?

Please suggest me how should I handle this?

1

There are 1 best solutions below

0
Jake W On

I suggest a solution as below:

The selection state/data and handling logic should be put in ParentPresenter.

ParentPresenter {
    List<String> selectedIds
}

In ChildPresenter1, whenever selection state changes, fire event to notify changes of selection (with selected or deselected ids). ParentPresenter will listen this event and update its selectedIds accordingly.

In ChildPresenter2, whenever 'Save' button is pressed, fire a SaveEvent, which is also listened by ParentPresenter. Once ParentPresenter receives this event, it can handle with all necessary information ready (selectedIds).