Place that dispatches to presenter bases on parameters

62 views
Skip to first unread message

David Nouls

unread,
Dec 1, 2016, 8:00:42 AM12/1/16
to GWTP
I'm a bit new to gwtp. The docs do not really go in much detail for more complicated setups.

I want to map a specific place to a presenter depending on parameters or even async information.
For example I have a url: message?id=messageId
This should load the details of that message and depending on meta info this should show one view or another one.

How do I do this with GWTP ? Can I somehow intercept an event and the implement some logic to start the right presenter ?

Harsh Yadav

unread,
Dec 4, 2016, 8:27:08 PM12/4/16
to GWTP
You can read the messageId from the history in your prepareFromRequest method of the presenter:

itsPlaceManager.getCurrentPlaceRequest().getParameter("id", "")


After, you have retrieved the message metadata, you can load appropriate view in different slots.

So for e.g. lets say you have 2 slots for 2 message types in your presenter:

public static final Slot SLOT_MESSAGE_1 = new Slot();
public static final Slot SLOT_MESSAGE_2 = new Slot();


And representing these 2 slots, your 2 presenter widgets:

private Message1PresenterWidget itsMessage1PresenterWidget;
private Message2PresenterWidget itsMessage2PresenterWidget;


depending on the message metadata, you set the appropriate slot:

if (message1) {
    setInSlot
(SLOT_MESSAGE_1, itsMessage1PresenterWidget);
} else if () {
   setInSlot
(SLOT_MESSAGE_2, itsMessage2PresenterWidget);
}

In your presenter's view, you'll need to have placeholders for these 2 slots

You can get more details here:


I would also recommend checking out the beestore example from Arcbees github:

David

unread,
Dec 5, 2016, 3:27:55 AM12/5/16
to GWTP
Thanks for the answer.

I guess one slot will be more than enough since they will never show at the same time. I already have such a thing setup in my main application presenter. I was hoping to have a presenter without a view but one that drives other presenters that will use the main application view slot.

What I am also missing a bit is how to share more than just some strings between presenters. (Through the place requests)

My main logic will call a REST service to load the contents of the message and then based on some custom criteria it will decide what sub-presenter will be handling the data. But I want to avoid loading the message twice.

Can I use a custom event that would include the message payload and somehow dispatch it to the child presenters ? I have seen some code that show a tab deck and it is using some annotations to determine the pages and to switch between them. Can I somehow do something similar ?
--
You received this message because you are subscribed to a topic in the Google Groups "GWTP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gwt-platform/CbshvsUFTqg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gwt-platform...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Harsh Yadav

unread,
Dec 5, 2016, 9:58:53 AM12/5/16
to GWTP
To share data b/w presenters, you can use the event-bus.

So for e.g. you have a main presenter, which shows some common data b/w multiple presenters.

------------Application Presenter (top-level application presenter)--------------
@ProxyStandard
public interface MyProxy
 
extends Proxy<ApplicationPresenter> {
}

------------Main Presenter (Nested inside application presenter slot. This also extends Proxy)----------------------
@ProxyStandard
public interface MyProxy
 
extends Proxy<MainPresenter> {
}

------------Child Presenter (1 or 2 as slots inside MainPresenter. These extend ProxyPlace)--------------
@NameToken (NameTokens.CHILD)
@ProxyCodeSplit
@NoGatekeeper
public interface MyProxy
 
extends ProxyPlace<ChildPresenter> {
}



Inside onReveal() of your MainPresenter, make the REST call, and fire the event (with data) via the EventBus.

Depending on which place (history token) you are at, the appropriate child presenter would receive that data, and show its content.
When you navigate to the second child presenter, it wouldn't have to do the REST call again, as it already has the data from the event bus.

Hope that answers your question or is the scenario you are facing.

David

unread,
Dec 5, 2016, 2:39:11 PM12/5/16
to GWTP
yes indeed. That is exactly what I needed? Thanks
Reply all
Reply to author
Forward
0 new messages