How do I pass parameters to a presenter?

145 views
Skip to first unread message

Gene Conroy-Jones

unread,
Jul 1, 2010, 8:07:32 PM7/1/10
to GWTP
I see from the overview of the library there is a well documented
section that shows how to reveal a presenter in code.

3) By manually revealing the proxy

Sometimes, however, using an Hyperlink is not possible and you will
need to reveal a proxy manually, within your code. For example, this
is what you need to do if you want to reveal a presenter when the user
clicks a button.

You do this by calling the revealPlace or one of the
revealRelativePlace method of PlaceManager. To do this you need to
build a PlaceRequest with the desired name token:

{{{
PlaceRequest myRequest = new PlaceRequest("desiredNameToken");
// If needed, add URL parameters in this way:
myRequest = myRequest.with( "key1", "param1" ).with( "key2",
"param2" );
placeManager.revealPlace( myRequest );
For an example of this, see MainPagePresenter.sendNameToServer() in
the sample application.
}}}

How do you pass a more complicated set of inputs to a presenter, say
for instance you were passing an address book of contacts from a
Google Contacts Import presenter to say a "Invite Friends to Join Your
Network" presenter? I understand one way might be to store them in
the database and do it that way. For arguments sake how would you do
it using the PlaceRequest object?

Cheers
G

Philippe Beaudoin

unread,
Jul 4, 2010, 10:56:02 PM7/4/10
to gwt-pl...@googlegroups.com
You can pass anything that you can serialize to a URL-friendly string
as a URL parameter, just do the serialization prior to the call to
"with". If it's too long, you might hit some URL size limit.

If you need to setup something more complex, however, it might be
better to consider "initializing" the presenter prior to calling its
name token. You can do that by firing an event containing the
initialization data. Consider using the new @ProxyEvent annotation for
that, since you probably want your presenter to "wake up" whenever the
event is sent. The drawback with the event approach is that you have
to provide some backup plan in the situation where the presenter is
invoked via the URL but it has never received the initialization event
before (ex: the user bookmarked the presenter). You can simply fail
(i.e. reveal the error place) or show information on some default
entity.

Hope it helps,

Philippe

Reply all
Reply to author
Forward
0 new messages