-
1. Re: redirecting from xhtml to jsp
niox.nikospara.yahoo.com Oct 1, 2009 5:32 PM (in response to jamesjmp)Hi,
Indeed the Javadocs for Redirect.setViewId() specify
Set the JSF view id to redirect to
. This is a JSF redirection, so it correctly translates the suffix.You need to get the response object from the ExternalContext, then call the sendRedirect() method. The response object is either HttpServletResponse for a servlet environment, or the corresponding class for a portlet environment, so you need to take care. After calling sendRedirect(), notify the JSF engine by calling FacesContext.responseComplete().
-
2. Re: redirecting from xhtml to jsp
jamesjmp Oct 2, 2009 11:07 AM (in response to jamesjmp)thank you. I tried it this way but it doesn´t work. No error displayed, no excepction catched but it doesn´t redirect. am I missing anything?
try { FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse respon = ((HttpServletResponse)context.getExternalContext().getResponse()); respon.sendRedirect("C:/ECLIPSE321/workspace/TAIE/view/jmp.jsp"); context.responseComplete(); } catch (Exception ex) { ex.printStackTrace(); }
btw, I use full path because I have an error if I just had
respon.sendRedirect("/jmp.jsp");
thank you!
-
3. Re: redirecting from xhtml to jsp
niox.nikospara.yahoo.com Oct 2, 2009 5:42 PM (in response to jamesjmp)respon.sendRedirect("C:/ECLIPSE321/workspace/TAIE/view/jmp.jsp");
Ouch! This is totally wrong!
The sendRedirect() commands the browser to load another URL. From the Javadocs:
If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.
.So if your JSF view is found at URL http://my.host.com/ctx/a/b/c.xhtml and you need to redirect to http://my.host.com/ctx/foo/bar.jsp try:
response.sendRedirect(request.getContextPath() + "/foo/bar.jsp");
You need to get the request object from the FacesContext, in a way similar to the response object.
This may still not work, if the current request is a RichFaces AJAX request. (Or it may work, I haven't tried it.) If it doesn't work indeed, we will figure out another way. But try this first.
Good luck!
-
4. Re: redirecting from xhtml to jsp
jamesjmp Oct 5, 2009 3:36 PM (in response to jamesjmp)thank you, it works that way!