I have 3 places which correspond to different regions,demo at http://demo4gwt.ecardbase.com/

43 views
Skip to first unread message

sugar_xj

unread,
Jun 14, 2011, 9:43:11 PM6/14/11
to Google Web Toolkit
the method I Override is the key to implement multiple place
----------
ActivityManager activityManager = new ActivityManager(cached,
eventBus){
@Override
public void onPlaceChange(PlaceChangeEvent event) {
if(event.getNewPlace() instanceof NorthPlace){
this.setDisplay(north);
}else if(event.getNewPlace() instanceof CenterPlace){
this.setDisplay(center);
}else if(event.getNewPlace() instanceof WestPlace){
this.setDisplay(west);
}else if(event.getNewPlace() instanceof AllPlace){
this.setDisplay(all);
}
super.onPlaceChange(event);
}
};
xxx.ui.xml is like this
<g:SimplePanel ui:field="all">
<g:DockLayoutPanel unit='PX' styleName="{style.bodyContainer}"
ui:field="dock">
<g:north size='270'>
<g:SimplePanel ui:field="north"/>
</g:north>
<g:west size='200'>
<g:SimplePanel ui:field="west"/>
</g:west>
<g:center>
<g:SimplePanel ui:field="center" styleName="{style.contents}" />
</g:center>
</g:DockLayoutPanel>
</g:SimplePanel>

first problem i got is when we press F5 or browser refresh
button,forward the url to others ,the app just loaded last place and
other places are blank ,so I changed the url like in demo ,then my
app is able to load all places,Now the problem i got is when user
press browser's 'back' button it works in same activity's different
place(place name is different) ,but it does not work go back between
different activity's place .

so any one please help me solve this problem.

Thomas Broyer

unread,
Jun 15, 2011, 8:24:28 AM6/15/11
to google-we...@googlegroups.com
Ouch! Total misunderstanding!

First, a Place is akin to a URL, it represents the "current state" of your app. Given a Place instance, you should be able to determine which Activity goes into each "region" (btw, that's the role of ActivityMappers to return an Activity given a Place).
You should have one ActivityManager *per* region you place Activities in; so you'll have 4 ActivityManagers, each one with its ActivityMapper, each one controlling a "display region". Given an "ExamPlace" for instance, the ActivityManager for the north region will ask its ActivityMapper which Activity (if any) to display (in the north region), the ActivityManager for the east region will ask its ActivityMapper which Activity to put in the east region, etc.
And the PlaceHistoryManager will turn the Place into an history token thanks to its PlaceHistoryMapper; that's what you see in the URL; and if you go back to that URL (copy/paste, bookmark, back/next in the browser), the Place will be built back from the token, dispatched on the event bus, and each ActivityManager will then reconstruct the Activity for its "display region".

For a more in-depth look, see http://tbroyer.posterous.com, where I wrote a couple articles on Places, and couple others on Activities.

sugar_xj

unread,
Jun 15, 2011, 11:45:30 AM6/15/11
to Google Web Toolkit
you said (a Place is akin to a URL, it represents the "current state"
of your app.),

in my app this url (http://demo4gwt.ecardbase.com/#exam:5--student:4--
menu:admin) represents 3 regions activity's lastPlaceName(with token),
current state is "exam:5",student:5 and menu:admin is other region's
last state, when user request a place it actually changes current
state's of url , other two tokenes shows us the other regions (which
not changed) last state,THE reason I changed URL is when user refresh
browser my app will load all regions places according to tokens in
url,

ExamActivity's start method is like this

public void start(AcceptsOneWidget panel, EventBus eventBus) {
panel.setWidget(display.asWidget());
String curr=History.getToken();
if(curr.startsWith(ExamPlace.TOKEN_NAME)&&curr.contains("--"))
{// if true ===refresh or forward the url.....
String[] places=curr.split("--");
for(int i=places.length-1;i>=0;i--){
History.newItem(places[i]);
}
}
}

------------------------------------------------------

I hava PlaceHistoryMapper and PlaceHistoryHandler ,it works well in
same Activity's different place(place name is different,try it on
http://demo4gwt.ecardbase.com/, load a place and click defferent page
NUM in the HTML tables page bar, then go back to previous page) ,but
it couldn't reconstruct the Activity (between different activity's
place) when I press go back . (click defferent menu item, then try to
go back to previous page). THAT is the problem.

I tried what you said (have 4 ActivityManagers, each one with its
ActivityMapper, each one controlling a "display region".)

in this case my app only displayed the requested place in correct
region,but other regions changed to blank, may be I didn't understand
exactly what you said , the code is :

NorthActivityMapper northActivityMapper =new NorthActivityMapper();
ActivityManager northActivityManager = new
ActivityManager(northActivityMapper,
eventBus);
northActivityManager.setDisplay(north);

CenterActivityMapper centerActivityMapper =new
CenterActivityMapper();
ActivityManager centerActivityManager = new
ActivityManager(centerActivityMapper,
eventBus);
centerActivityManager.setDisplay(center);

WestActivityMapper westActivityMapper =new
WestActivityMapper();
ActivityManager westActivityManager = new
ActivityManager(westActivityMapper,
eventBus);
westActivityManager.setDisplay(west);

----------------------------------------------------------------------

Other region dispaly blank is because of the code in XXXActivityMapper
is like this:

public Activity getActivity(Place place) {

if(place instanceof XXXPlace){
Activity activity=((XXXPlace) place).getActivity();
return activity;
}
return null;
}

if the code should not like this ,why should I have 4 ActivityMapper?

and please tell me what should I do to make my app to be able to load
differrent region's activity when user refresh the browser(http://
demo4gwt.ecardbase.com/#exam:5 it cant load all 3 region's last
state,but current state ),when user A forward the url to user B,user B
should see 3 regions display just like user A are looking right
now,not only one.
> For a more in-depth look, seehttp://tbroyer.posterous.com, where I wrote a

Thomas Broyer

unread,
Jun 15, 2011, 12:11:42 PM6/15/11
to google-we...@googlegroups.com
I'm totally lost as to how your (sample) app is expected to behave.

Still, "exam:5--student:4--menu:admin" represents "somewhere", some instance of some Place class that holds this "state". You'll have a PlaceTokenizer building this instance from that token.
then, when the place is given to any of the 3 ActivityMappers (one per region; sorry, I misread, and though you had 4 regions), each one will tell which activity to display in the region it controls.

So, the NorthActivityMapper will look at the place and return an ExamActivity for the 5th page (if I understood correctly); the WestActivityMapper will return an AdminMenuActivity (or whatever), and the CenterActivityMapper will return a StudentActivity for the 4th page.

When you want to navigate, you goTo a place that holds the whole state, so that each ActivityMapper will answer accordingly to what should be displayed in "their" region, adn the URL will be updated accordingly.
In your case, your place is kind of a "composite", where the "center activity" doesn't particularly care what is in the north region; so I'd suggest building the new place from the current one, just modifying the part that needs to change; something like:

   placeController.goTo(MyPlace.student(5, placeController.getCurrentPlace());

The student() factory method would then "copy" the exam:5 and menu:admin bits from the current place and set the "student" part to 5, so you really "goTo exam:5--student:5--menu:admin".

In brief, there would only be a single type of Place that can tell you exactly what should be "displayed"; and each ActivityMapper then use what it needs to know from the place to put the correct activity into the slot it manages.
Reply all
Reply to author
Forward
0 new messages