Have you ever noticed that when your application uses a lot of Ajax features to replace Panels, the user looses the ability to use the back/forward buttons of his browser, or even to bookmark the page?
If there was a lot of Ajax browsing (panel replacements), when the user clicks on the back or the refresh button the browser will take him to the last visited page, or even to his home page.
My goal here was to provide a set of functions allowing the developper to change the token in the URL, but also to add a behavior listening to the token changes.
1. If you call
TokenManager.changeToken("newtoken", target);
the new URL will be http://localhost:8080/home#newtoken
1. If you add a DefaultTokenValueChangeAjaxBehavior (requires IE8+) or a JqueryTokenValueChangeAjaxBehavior (requires jquery.js)
add(new DefaultTokenValueChangeAjaxBehavior() { @Override public void onTokenChanged(AjaxRequestTarget target, String token) { target.appendJavaScript("alert('ontokenchanged:" + token + "');"); } });
you will be notified each time the token changes; for example if the uses presses the back button, or if the TokenManager.changeToken method is called.
You can have a look at the project here : https://github.com/vmontane/wicket-ajax-bookmarks.
There is also a demo project with a simple
How to start the demo in a few command lines : - get the project on github
git clone git://github.com/vmontane/wicket-ajax-bookmarks.git wicket-ajax-bookmarks
- build wicket-ajax-bookmarks
cd wicket-ajax-bookmarks/wicket-ajax-bookmarks mvn install
- build wicket-ajax-bookmarks-example
cd ../wicket-ajax-bookmarks-example mvn install
- run the application with the jetty maven plugin
mvn jetty:run
That's all ! Now you can browse to http://localhost:8080 and start playing with the demo.
Here's what the demo does:
An Ajax DropDownChoice allows you to change a panel. I added a DefaultTokenValueChangeAjaxBehavior to the page and overrode the onTokenChanged method, which is called each time the token changes in the browser (ie. when the user clicks the next/previous button, or when he switches panel).
When the onTokenMethod is called, a JavaScript 'alert(token);' is called so you can see what has been caught on the server, and the current panel is changed.
Note that this projetct uses some elements of Wicket 1.5 and has not been tested with Wicket 1.6-beta. If you wish to contribute or ask for new requests don't hesitate to contact me.

