Passing an argument to a View using Activities and Places

39 views
Skip to first unread message

Mike Dee

unread,
Oct 6, 2011, 1:17:25 PM10/6/11
to Google Web Toolkit
I'm using Activities and Place and can't figure this out. I've been
looking at samples but don't see it in there. I think I'm missing
something.

I have a button in one place that, when clicked, will trigger a new
activity and place (along with a new view). The code for that button
simply looks like this:

listener.goTo( new FooPlace( fooid ) );

The above code is in the button handler of BarViewImpl (view
implementation for a separate place/activity).

This above line works in that it goes to FooPlace and the URL shows
the parameter (123456):

MyApp.html?gwt.codesvr=127.0.0.1:9997#FooPlace:123456

But fooid doesn't make it to FooView. How does the FooPlace or
FooActivity pass the fooid to FooView?

Mike Dee

unread,
Oct 6, 2011, 1:25:11 PM10/6/11
to Google Web Toolkit
Just want to add one thing. FooView has a method named setName(),
which (I think) is used to set the argument. I've noticed this is not
called, even though it is passed in creating the FooPlace.

Alisson Prestes

unread,
Oct 6, 2011, 1:44:20 PM10/6/11
to google-we...@googlegroups.com
The FooActivity extracts the arguments from the FooPlace. Then it calls the right method in the FooView. Place and View do not interact with each other directly.

Alisson Prestes



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Mike Dee

unread,
Oct 6, 2011, 1:46:31 PM10/6/11
to Google Web Toolkit
So, should I put code in FooActivity? I am not sure if the
boilerplate code generated by the activity should have done that or
not.

Mike Dee

unread,
Oct 6, 2011, 1:48:20 PM10/6/11
to Google Web Toolkit
Would the call to set the arg in the view go in FooActivity.start()?

Alisson Prestes

unread,
Oct 6, 2011, 1:51:40 PM10/6/11
to google-we...@googlegroups.com
Yes, I think this will work.


Alisson Prestes

Mike Dee

unread,
Oct 6, 2011, 2:00:07 PM10/6/11
to Google Web Toolkit
FooActivity.start() looks like this. Note that while it can get
FooView from the clientfactory, it has no notion of FooPlace, which is
where the argument (fooid) is stored.

@Override
public void start( AcceptsOneWidget containerWidget, EventBus
eventBus )
{
FooView view = clientFactory.getFooView();
view.setPresenter( this );
containerWidget.setWidget( view.asWidget() );
}

I guess the call to view.setName() could be made in FooActivity's
constructor, where a FooPlace is passed in.

public FooActivity( FooPlace place, ClientFactory clientFactory )
{
this.clientFactory = clientFactory;
}

But I don't know how to get the argument (token) out of FooPlace.


On Oct 6, 10:51 am, Alisson Prestes <javalis...@gmail.com> wrote:
> Yes, I think this will work.
>

Alisson Prestes

unread,
Oct 6, 2011, 2:16:53 PM10/6/11
to google-we...@googlegroups.com
Here's an example from "GWT Development with Activities and Places" tutorial (http://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html)

public class HelloPlace extends Place {
   
private String helloName;

   
public HelloPlace(String token) {
       
this.helloName = token;
   
}

   
public String getHelloName() {
       
return helloName;
   
}

   
public static class Tokenizer implements PlaceTokenizer<HelloPlace> {
       
@Override
       
public String getToken(HelloPlace place) {
           
return place.getHelloName();
       
}

       
@Override
       
public HelloPlace getPlace(String token) {
           
return new HelloPlace(token);
       
}
   
}
}
As you correctly guessed, in the constructor you call the "get..." method and stores it in an attribute, just like you did with the clientFactory. Then you can check if this attribute is not null in the start method and call the appropriated method of the view.

Alisson Prestes

Jens

unread,
Oct 6, 2011, 4:38:44 PM10/6/11
to google-we...@googlegroups.com
Your FooPlace should have a getter method to return the stored id. In your ActivityMapper you create an activity for a given place. When you create your activity you can pass the place into its constructor or via a separate setPlace(Place place) method. Your activity would then call the getter of the FooPlace to get the id stored in the place and store it in a variable.

The AppActivityMapper constructs a HelloActivity and passes in the given HelloPlace. Then the HelloActivity calls HelloPlace.getName() in its constructor and stores the value. In HelloActivity.start() you can then use the value to make database calls, configure your view or whatever you need to do.

Mike Dee

unread,
Oct 8, 2011, 1:10:52 PM10/8/11
to Google Web Toolkit
Jens, Allison,

Yes, I see my problem. I even used the GWT MVP View wizard to create
the Place, Activity, and View. It very nicely generates template
classes - with the FooPlace.setName(). I must have deleted the method
in FooPlace at some point.

Thanks,
Mike

On Oct 6, 1:38 pm, Jens <jens.nehlme...@gmail.com> wrote:
> Your FooPlace should have a getter method to return the stored id. In your
> ActivityMapper you create an activity for a given place. When you create
> your activity you can pass the place into its constructor or via a separate
> setPlace(Place place) method. Your activity would then call the getter of
> the FooPlace to get the id stored in the place and store it in a variable.
>
> Take a look
> athttp://code.google.com/intl/de-DE/webtoolkit/doc/latest/DevGuideMvpAc...
Reply all
Reply to author
Forward
0 new messages