GWTP Presenter prepareFromRequest - loading data into a form obtained from an event

I have tried GWTP over the past few weeks and have been creating a small project with it.

Here's the question:

I have a grid widget (attached screenshot) that shows a list of data. When I select the line checkbox and click on Edit Request , I get to the details page. Summary Page

Since I have all the data (model) that will be shown on the details page in the very view of the final screen, I do not want to retrieve it from the database again.

So, I did the following:

  • When I select and click on the edit request, I get the selected model
  • Request a place on the details page
  • Fire a edit event and pass the selected model as a parameter.

I understand that I am doing this wrong, because when I select an item and click Edit Request , the details page does not yet receive the selected item. It simply shows a blank page without filling in the data (obviously, because the place was reached long before the event was 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 conceivable solution . Instead of triggering an event, I could do a placerequest with the parameter of the selected id element, and then override useManualReveal and prepareFromRequest to retrieve data from the database.

But is there a way to avoid calling the database for pre-existing data.

+4
source share
2 answers
  • If you want to keep the current "RequestEditEvent" solution, be sure to use @ProxyEvent (see http://code.google.com/p/gwt-platform/wiki/GettingStarted?tm=6#Attaching_events_to_proxies ).

  • Another possibility may be to invert the direction of the event: in your data presenter, run an event that requests data from the host.

  • However, when using the same data for several presenters, it might be a good idea to store the data in a central model: create a model class (@Singleton) and enter it wherever needed. Then you can search (by id) from this local model, and not query the server. In this case, you do not need any events - only somewhere, for example. as a location parameter or even as the "currentItemId" in the model.

+1
source

Based on @Chris Lercher's answer, I used ProxyEvent. Implementation details are as follows.

In my RequestEditPresenter (detail presenter), I applied the RequestEditHandler event RequestEditHandler , as in

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

then in the same RequestEditPresenter override the method in 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 Place , I used placeManager. For presenters who do not have a NameToken , just call the forceReveal() method

0
source

All Articles