Simple history question

29 views
Skip to first unread message

Navigateur

unread,
Jan 27, 2011, 11:32:52 AM1/27/11
to Google Web Toolkit
Before I delve, what's the most elegant way of handling the start page
of your app? (i.e. going back to it?)

Really my question is about the fact that for e.g. "page2" you have
created a history token with the String "#page2"... but when you press
the "back" button after this, you go back to the first page that
has... no token? So how do you test for this?

Sorry if this sounds stupid (and I haven't done it yet)... but does
the ValueChangeHandler just give you a token with an empty String ("")
when you do this?

If not, what's the most elegant way of including the first page in
your history, without repeating any code, and without adding
unnecessary items in the browser history?

Ryan Mehregan

unread,
Jan 27, 2011, 11:54:08 AM1/27/11
to google-we...@googlegroups.com
PlaceHistoryHandler, has a register method:

public HandlerRegistration register(PlaceController placeController,
                                                  EventBus eventBus,
                                                  Place defaultPlace) {

you probably have already defined some places in your application.
just pass the one you want to make the default (start) place,
to the register method.

have a look at the code here:
http://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html#Putting_it_all_together

Ryan

Navigateur

unread,
Jan 27, 2011, 12:01:32 PM1/27/11
to Google Web Toolkit
Ah "Places". This is only in GWT 2.1, right?

Ok, how would I do it in a 2.0 app using "History"?

And if I upgraded to 2.1, what are the basic advantages of using
"Places" over "History"?

Cheers,
N
> have a look at the code here:http://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAnd...
>
> Ryan

Ryan Mehregan

unread,
Jan 27, 2011, 12:26:21 PM1/27/11
to google-we...@googlegroups.com
Places use History mechanism behind the scenes.
It is an abstraction layer which allows you to deal with History from a higher level point of view,
and application oriented.

in GWT applications, unlike other traditional web frameworks,
we have only one .html page. therefore talking about page1, and page2,is not correct,
because there is only one .html page.
but to enrich user experience, making your app navigable, bookmarkable,
back and forward button to work, you need to manipulate history.
instead of dealing with History directly, which is low level, you use Places,
as a result you can have different places in your app.
HomePlace, AccountsPlace, EmployeePlace, EmployeeListPlace.

and this is not just terminology differences. Places are integrated with EventBus,
so as you navigate from one place, to another, PlaceChangeEvents get fired.
and you can write code to handle these event changes.

For example, when you have a list of employees. when you click on (select) an employee on the list,
your app can take the user to a new place (employee detail place), to display detailed info on the selected employee.

Please have a look at these two very well written articles on Places.

GWT 2.1 Places part 1 : http://tbroyer.posterous.com/gwt-21-places
GWT 2.1 Places part 2: http://tbroyer.posterous.com/gwt-21-places-part-ii

Places are an integral part of GWT MVP framework, related to Activities.

if you are not already using GWT MVP, I do not think there would be any benefit in using Places.
only adds unnecessary complexity and huge learning curve.

I do not know how what you want to do can be achieved elegantly using raw History tokens.

Ryan

Thomas Broyer

unread,
Jan 27, 2011, 2:05:05 PM1/27/11
to google-we...@googlegroups.com


On Thursday, January 27, 2011 5:32:52 PM UTC+1, Navigateur wrote:
Before I delve, what's the most elegant way of handling the start page
of your app? (i.e. going back to it?)

Really my question is about the fact that for e.g. "page2" you have
created a history token with the String "#page2"... but when you press
the "back" button after this, you go back to the first page that
has... no token? So how do you test for this?

Sorry if this sounds stupid (and I haven't done it yet)... but does
the ValueChangeHandler just give you a token with an empty String ("")
when you do this?

Yes.
 
If not, what's the most elegant way of including the first page in
your history, without repeating any code, and without adding
unnecessary items in the browser history?

The easiest way is to start your ValueChangeHandler with code like:
  if (historyToken.isEmpty()) {
    historyToken = DEFAULT_TOKEN;
  }
 
or to only ever associate that "default page" with the empty token.

This is similar to whether you'd link to "/index.html" (default name used by your web server when asked for "/") or "/" (and never ever use "index.html" in your links).

I'd highly suggest you to use GWT 2.1 Places though!
Reply all
Reply to author
Forward
0 new messages