Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 329818

Summary: Add API to navigate to a different site
Product: [RT] RAP Reporter: Michal Tkacz <Michal.Tkacz>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: eclipse, info, ivan, rsternberg, stefan.roeck, tbuschto
Version: 1.3   
Target Milestone: 2.0   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Michal Tkacz CLA 2010-11-09 10:48:23 EST
Currently using RWT.getResponse().sendRedirect(url) results in a message dialog saying "The server seems to be temporarily unavailable. Would you like to retry?". Pressing Cancel leads to a page saying "Request failed. HTTP Status Code: 0" message. Pressing OK results in another message box page saying "Multiple browser-instances or browser-tabs per session are not supported. You may click OK for restarting the session."

The hack described in the newsgroups ([1]) is... ugly. Please make the RWT.getResponse().sendRedirect(url) work as expected.

[1] http://dev.eclipse.org/newslists/news.eclipse.technology.rap/msg02659.html
Comment 1 Karsten Voigt CLA 2011-03-11 15:39:35 EST
I also have that problem. It is not possible to send the redirect. (I'd like to redirect on button click).
Comment 2 Ralf Sternberg CLA 2011-03-11 16:43:11 EST
Could you please outline your use case? Why would you want to redirect an Ajax request? Do you want to replace the page currently displayed in the browser?
Comment 3 Michal Tkacz CLA 2011-03-12 18:47:29 EST
I think I understand what you're trying to say. Maybe RWT.getResponse().sendRedirect(url) is not the right method to use when one wants to redirect user to another page (because it's a response to an Ajax request). But if that's the case, then it would be nice to have such a method, because the only way to do it now that I'm aware of is the one described in first comment and it's cumbersome. This method could send url to the browser so that the client-side javascript redirect the user to the specified page.
Comment 4 Ralf Sternberg CLA 2011-03-13 05:53:17 EDT
(In reply to comment #3)
Exactly, RWT.getResponse().sendRedirect(url) redirects the Ajax request and cannot change the page in the browser. But I agree that there should be a way to do that with public API. Changed the title accordingly.

Currently, the workaround is to use:

 HtmlResponseWriter writer = ContextProvider.getStateInfo().getResponseWriter();
 writer.write( "parent.window.location.href=\"" + url + "\";" );
Comment 5 Michal Tkacz CLA 2011-03-13 05:55:22 EDT
Great, this workaround is much shorter than the previous one.
Comment 6 Kees Pieters CLA 2012-10-21 08:23:47 EDT
I've just ried to perform a redirect as suggested in the workaround, with RAP 1.5, but the HtmlResponseWriter seems to be gone (see bug 340927). Is there an alternative way to redirect to a new webpage from a hyperlink implemented in RWT?
Comment 7 Ralf Sternberg CLA 2012-10-22 07:29:57 EDT
HtmlResponseWriter is gone, as there are no HTML or JavaScript responses anymore. In RAP 1.5, you can use this internal API:

  JSExecutor.execute( "parent.window.location.href=\"" + url + "\";" );

As of RAP 2.0 M3, there's finally public API to execute JavaScript on the client, see this post: http://eclipsesource.com/blogs/2012/10/17/javascriptexecutor-is-now-api/
For further questions, please use the forum.
Comment 8 Kees Pieters CLA 2012-10-22 09:17:50 EDT
(In reply to comment #7)
> HtmlResponseWriter is gone, as there are no HTML or JavaScript responses
> anymore. In RAP 1.5, you can use this internal API:
> 
>   JSExecutor.execute( "parent.window.location.href=\"" + url + "\";" );
> 
> As of RAP 2.0 M3, there's finally public API to execute JavaScript on the
> client, see this post:
> http://eclipsesource.com/blogs/2012/10/17/javascriptexecutor-is-now-api/
> For further questions, please use the forum.

Tested it and it seems to work ok, apart from a typo:

    JSExecutor.executeJS( "parent.window.location.href=\"" + url + "\";" );

I guess that this bug can be closed then ;)

Thanks for the quick response

Kees
Comment 9 Ralf Sternberg CLA 2012-10-22 10:50:00 EDT
As of bug 388249, the client also accepts a "redirect" parameter in the message header.
@Tim: what about a redirect service/method for the WebClient?
Comment 10 Ivan Furnadjiev CLA 2014-07-21 07:54:59 EDT
As of RAP 2.0 we also have UrlLauncher client service.
Comment 11 Ralf Sternberg CLA 2014-07-22 03:43:46 EDT
(In reply to Ivan Furnadjiev from comment #10)
> As of RAP 2.0 we also have UrlLauncher client service.

Are you sure this service can be used to replace the *current* page with another one? I think this is what this bug requested.
Comment 12 Ivan Furnadjiev CLA 2014-07-22 03:54:58 EDT
(In reply to Ralf Sternberg from comment #11)
> (In reply to Ivan Furnadjiev from comment #10)
> > As of RAP 2.0 we also have UrlLauncher client service.
> 
> Are you sure this service can be used to replace the *current* page with
> another one? I think this is what this bug requested.

The UrlLauncher does not replace the current (RAP application page). Based on comment#8 JavaScriptExecutor can be used successful in this case and there is no need for other API.