Acivities and Places - passing by reference

25 views
Skip to first unread message

dparish

unread,
Feb 2, 2012, 3:23:15 PM2/2/12
to Google Web Toolkit
I'm refactoring a MVP app I have that currently uses Events and an
AppController to handle navigation transitions.

Activities and Places appear to only pass state via tokens, not by
passing by reference. is there another way?

A use case may help here:
Think of two screens, A Student List screen and an Add Edit Student
screen.

Without places using events, clicking on a Student in Student List
fires off an event CONTAINING the student, so when the Add Edit
Student view picks it up, it already knows about the student.

With Places when you click on a student in student list, the
PlaceManager gives you a place and an id for that student. The Add
Edit Student Actiivity has to look up the student based off the passed
in id. This seems like a major design drawback. What I was expecting
was some method to pass the object. In the case where someone
navigates straight to:

#AddEditStudentPlace:2

I would expect my code to handle the fact that it does not have a
passed in student and in THAT case, fetch it from the server. If
you've already clicked on the Student in a list view, it's insane to
look it up again. That's about as un GWT as you can get.

Yes I could put it in a app cache, but that's a hack and introduces
client side memory issues.

There must be some way to handle this that keeps the model simple.

The only thing I can think of is putting my events back in on top of
places, but what good is that?? If I do that, why even use Places?


John99

unread,
Feb 2, 2012, 3:44:20 PM2/2/12
to google-we...@googlegroups.com
you need to put your student into EditStudentPlace and initialize new EditStudentActivity with it in ActivityMapper

dparish

unread,
Feb 2, 2012, 4:38:46 PM2/2/12
to Google Web Toolkit
SWEET. That was exactly it. I added a setStudent and getStudent to
StudentAddEditPlace

In my activity mapper I get the activity for the place, then set the
student into the activity that I get from the place.

Subtle but obvious now that I see it. Thank you very much.

-Dave

-sowdri-

unread,
Feb 3, 2012, 1:37:07 AM2/3/12
to google-we...@googlegroups.com
Hi, If you want activities to be talking to each other, one way of achieving them is via encapsulating the data in the Place, as mentioned above. 

Imagine a complex application, where in a lot of objects are required by different activities. In events like that, you have to pass on all the required objects through Place(s). Which is kind of chain, where sometimes, some values have to be passed just to enable the construction of all the possible places/activities that could be triggered from there. 

A simple solution on that case could be to have  a singleton value store, and use it for value types. 

@Singleton
public class ValueStore {

private Map<String, Object> values = new HashMap<String, Object>();

public Object getValue(String key) {
return values.get(key);
}

public void putValue(String key, Object value) {
values.put(key, value);
}

public boolean hasValue(String key) {
return values.containsKey(key);
}
}

Such that the data populated in one activity could be consumed by a host of other related activities. 

Just another way of achieving the same! 
Reply all
Reply to author
Forward
0 new messages