I’ve a gwt application, and in some moment a applet its opened, and when this applet executes a action it calls a servlet.
From this servlet, i need to redirect the application to the Token “#Home”.
I tried to call History.newItem(“#home”), but it returns a exception “Unsuported operation in server side”.
I tried to return to applet again from servlet, and in the applet call a javascript exported with jnsi that redirects to home, but it not works too, the navigator (google chrome) can see my exported function, but when called in applet it gives a error “function not found”
Thanks for any help.
I’m guessing that by Applet you don’t actually mean a Java applet but the HTML and Javascript generated by GWT from the client Java code. Make sure not to confuse these notions. Your GWT project has client Java code (which is converted to HTML and CSS at compilation) and server Java code, which is deployed on the server as is. It makes no sense to call History.newItem(…) on the server side, that’s code that should go in your client Java, so that it will be translated to Javascript and called in the browser (navigation history only makes sense in the browser).
Also, what you want to do here is not make an HTTP Redirect per-se, but only to navigate to a different GWT page/widget by using the anchor that’s attached to it. And I’m guessing you want this to also be put in the history of the browser’s navigation so that the user can use the browser’s “back” and “forward” buttons properly. For this you need to simply implement the
ValueChangeHandler<String>interface on your GWT main class, implement thepublic void onValueChange(ValueChangeEvent<String> event)and parse the recieved anchor from the event and change your view accordingly. Then, when the user clicks a button or something, you user the History class to isse a new event, something like this:(true means that an event will be generated. Otherwise you’ll just add the “home” token to the history stack of the browser).
This will call the
onValueChange(...)with an event that contains the “home” token, and there you can parse that token and do whatever you want.http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/History.html#newItem(java.lang.String, boolean)