How to show a User view in GWT app by typing in browser address bar

28 views
Skip to first unread message

Xybrek

unread,
Aug 22, 2011, 12:15:23 PM8/22/11
to Google-We...@googlegroups.com
I have this gwt app which say, runs on http://mygwtapp.com/ (which is
actually: http://mygwtapp.com/index.html)

The application 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

I have tried using GWT Fragment Identifier approach well and works well
when the app is in debug mode and when deployed in Tomcat it works when
the main page has loaded already. This approach though it works the page
is not bookmark-able, i.e. when users type
http://myapp.com/index.html#user123 in the browser I get a blank page.

Is there any way to achieve this kind of feature?

Jens

unread,
Aug 22, 2011, 1:08:56 PM8/22/11
to google-we...@googlegroups.com, Google-We...@googlegroups.com
You have to use redirect rules on your web server, e.g. nginx, apache, tomcat, etc. That way you can deliver your app's index.html for different URLs based on regular expressions. Once your server delivers your index.html you can do Window.Location.getPath() in your EntryPoint and then do whatever you have to do.

The only downside is, that if your user names doesn't follow a specific pattern then you have to redirect nearly every request to your index.html (you would exclude your GWT-RPC/RequestFactory servlet URLs and in general all URLs that point to a file that really exists on your server). So you loose HTTP 404 errors on your web server because you can not decide if the request, that will point to a folder/file that does not exist on your server, e.g. /user123, is wrong and you should do a 404 or if its wrong but you have to redirect to index.html. If you want to keep 404's I think you have to change your desired URL to something like:
http://app.com/u/<username>. That way you could redirect only if you receive a request that starts with /u/.

A nice way to make your GWT pages bookmarkable is to use GWT's places framework. GWT Places uses the hash fragment of the URL to store information about the place (what place is active and what application state belongs to that place).

-- J.

Xybrek

unread,
Aug 22, 2011, 2:43:46 PM8/22/11
to Google-We...@googlegroups.com
> --
> You received this message because you are subscribed to the Google
> Groups "Google Web Toolkit" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/7QUWpvMPDw8J.
> 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.


So you mean with gwt places when user type in the browser url like
http://mygwtapp.com/user456 it will show the view for the user? Even if
user page has not been browsed in the browser used? I am really
unfamiliar with gwt places.

Jens

unread,
Aug 22, 2011, 4:20:53 PM8/22/11
to google-we...@googlegroups.com, Google-We...@googlegroups.com
Well it would, but your problem is your URL requirement. 

With standard GWT Places your URL would look like: http://mygwtapp.com/#UserPlace:<unique username or db id> or if you customize GWT Places you could achieve URLs like http://mygwtapp.com/#/user/<unique username or db id>. So as you can see GWT places also uses the hash fragment of an URL to store information.  So you should only use it if you can change your URL requirement to something that GWT places is able to give you. 

If you really need this URL requirement then your only chance is to configure your server side rewrite correctly so that your app starts and read the URL path from within your app. Your app then has to decide what to do when it sees the path "userXYZ" or something other.

-- J.





Reply all
Reply to author
Forward
0 new messages