0

I have this gwt app which say, runs on http://mygwtapp.com/ (which is actually: http://mygwtapp.com/index.html)

The app host a database of users, queried by searching usernames using the search view and results are shown in the user results view. Pretty useful enough. However I need to bb add a way that user view can be viewed by just typing http://myapp.com/user123

I am thinking that the question I have here, the answer is a server side solution. However if there's a client side solution, please let me know.

One fellow here in StackOVerflow suggested that the format would be like this: mygwtapp.com/index.html#user123

However the format is important to be like: http://myapp.com/user123

quarks
  • 33,478
  • 73
  • 290
  • 513

2 Answers2

1

mygwtapp.com/index.html#user123 That would be using the History mechanism (http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsHistory.html) which I would add is the recommended way of doing it.

However, if you insist on using something like http://myapp.com/user123, one of the possible ways is to have a servlet which accepts this request (you might have to switch to something like http://myapp.com/details?id=user123). The servlet will look up the DB and return your host html back. Before returning it will inject the required details as a Dictionary entry in the page (http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/i18n/client/Dictionary.html) On the client you can read this data and display on the UI

maneesh
  • 1,692
  • 1
  • 14
  • 18
  • I assume with this solution after the servlet the browser url will show http://myapp.com/details?id=user123 and not http://myapp.com/user123 – quarks Aug 21 '11 at 16:15
1

The 'something' in 'http://host/path#something' is a Fragment identifier. FIs have a specific feature: the page isn't reloaded if only FI part in URL changes, but they still take part in browser history.

FI's are a browser mechanism that GWT uses to create "pages", i.e. parts of GWT application that are bookmarkable and have history support.

You can try to use an URL without # (the FI separator), but then you will have a normal URL, that reloads the page with every change and it could not be (easily) a part of a normal GWT app.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • yes I have tried FI, however what I have done is to a add a code inside the ValueChangeHandler which updates the model based on the event.getValue (which is the string typed, say #user123) then finally switch to the user view, this works when the app is running in hosted/debug mode, however does not work when bookmarked and reloaded in the browser, when deployed as tomcat webapp. Any idea how to fix this? – quarks Aug 22 '11 at 06:48
  • Hard to say what is wrong without seeing the code. Do you call `History.fireCurrentHistoryState()` after you registered your history handler? – Peter Knego Aug 22 '11 at 11:13
  • Please check this link to see how I implemented the code somehow: http://stackoverflow.com/questions/7144038/gwt-fragment-identifier-works-in-hosted-mode-and-not-in-compiled-mode-tomcat – quarks Aug 22 '11 at 11:37
  • 1
    When you are registering history handlers the history event has already happened. You need to "re-fire" the event again after the handler is registered. Try adding `History.fireCurrentHistoryState()` after your `History.addValueChangeHandler(..)` – Peter Knego Aug 22 '11 at 12:53
  • 1
    http://stackoverflow.com/questions/6925228/what-is-need-history-firecurrenthistorystate-in-gwt-history/6926545#6926545 – Peter Knego Aug 22 '11 at 12:54