4

I have been trying GWTP for the past couple of weeks and building a small project with it.

Here's the question :

I have a grid widget (attached screenshot) which shows a list of data. On selection of a checkbox of a row and clicking on Edit Request, I get into a detail page. Summary Page

Since I have all the data (model) to be shown in the detail page in the summary screen presenter itself, I don't want to fetch it from the database again.

So, I did the following :

  1. On selection and clicking edit request, I get the selected model
  2. Make a place request to the detail page
  3. Fire an edit event and pass the selected model as parameter.

I understand that I am doing it wrong because when I select an item and hit Edit Request, the detail page does not receive the selected item yet. It just shows a blank page with no data filled in (obviously, because the place has been reached much before the event has been fired).

Current code :

RequestModel selectedItem = getView().getGrid().getSelectionModel().getSelectedItem();

PlaceRequest placeRequest=new PlaceRequest(NameTokens.initiationedit);  
getEventBus().fireEvent(new RequestEditEvent(selectedItem, PHASE_INITIATION));

placeManager.revealPlace(placeRequest);

Personally thought solution : Instead of firing an event, I could make a placerequest with a parameter of the selected item's id and then override the useManualReveal and the prepareFromRequest to fetch data fresh from database.

But is there a way I could avoid database call for the pre-existing data.

Arun Manivannan
  • 4,213
  • 3
  • 29
  • 38

2 Answers2

1
  1. If you want to keep your current "RequestEditEvent" solution, then make sure to use @ProxyEvent (see http://code.google.com/p/gwt-platform/wiki/GettingStarted?tm=6#Attaching_events_to_proxies).

  2. Another possibility may be to invert the direction of the event: In your details presenter, fire an event which requests data from the overview presenter.

  3. However, when using the same data across multiple presenters, then it may be a good idea to keep the data in a central model: Create a model class (@Singleton) and inject it everywhere you need it. Then you can make a lookup (by id) from that local model instead of asking the server. In this case, you don't need any events - just the id somewhere, e.g. as a place parameter, or even as a "currentItemId" in the model.

Chris Lercher
  • 37,264
  • 20
  • 99
  • 131
0

Based on the answer by @Chris Lercher, I used the ProxyEvent. The implementation details are as follows.

In my RequestEditPresenter (the details presenter), I implemented the event handler RequestEditHandler as in

public class RequestEditPresenter extendsPresenter<RequestEditPresenter.MyView, RequestEditPresenter.MyProxy> implements RequestEditHandler{

then in the same RequestEditPresenter override the method in the RequestEditHandler as in

@Override
@ProxyEvent
public void onRequestEdit(RequestEditEvent event) {

    getView().setModelToView(event.getRequestModel());

    ...various other initiation process...

    placeManager.revealPlace(new PlaceRequest(NameTokens.initiationedit));
}

Since the Details presenter was a Place, I used the placeManager. For presenters that do not have a NameToken, just call the forceReveal() method

Arun Manivannan
  • 4,213
  • 3
  • 29
  • 38