You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Sorin Silaghi <so...@gmail.com> on 2007/03/29 12:59:32 UTC

redirect question

Hello,

      This is a really easy one.. how can i redirect from the backing bean
to something that is not jsf... like to an external link for example ???

I've tried the whole

            HttpServletResponse response = (HttpServletResponse)
facesContext.getExternalContext().getResponse();
            response.sendRedirect(url);
            facesContext.responseComplete();

but it dosen't work the way I expect it to.. I presume this just redirects
to another JSF page right ? ... so how do I convince it to go to
google.comfor example ???

Re: redirect question

Posted by CD <dc...@gmail.com>.
If it is a servlet, redirect like so:

response.sendRedirect(response.encodeRedirectURL("/servlet"));


On 3/29/07, CD <dc...@gmail.com> wrote:
>
>
>
> On 3/29/07, Sorin Silaghi <so...@gmail.com> wrote:
> >
> > I am using it as a hack for JSCookMenu :D ....Sadly it didn't work this
> > way ... the thing is the URL I'm sending it to is in the same application
> > but it's a servlet, not a JSF page. I'll try in the morning again maybe i've
> > missed something...
> >
> > 10x
> >
> > On 3/29/07, CD <dc...@gmail.com> wrote:
> > >
> > > Any particular reason you are performing a redirect (I'm assuming you
> > > are using this as a command link) rather than just using a standard output
> > > link?
> > >
> > > Regardless of the answer, I am in agreement with David.  One
> > > suggestion I can make is to be sure you encode the redirect url with the
> > > response.encodeRedirectURL() method.  To redirect to an external site
> > > outside of the application context, you will need to supply an absolute URL.
> > >
> > >
> > > HTH,
> > > CD
> > >
> > >
> > >  On 3/29/07, David Delbecq <delbd+jakarta@oma.be > wrote:
> > > >
> > > > This is the way to go. However it will throw an exception is
> > > > response
> > > > has already been committed.
> > > > also the url must be either full ("http://......") either an url
> > > > relative to current webapplication.
> > > >
> > > > Sorin Silaghi a écrit :
> > > > > Hello,
> > > > >
> > > > >       This is a really easy one.. how can i redirect from the
> > > > backing
> > > > > bean to something that is not jsf... like to an external link for
> > > > > example ???
> > > > >
> > > > > I've tried the whole
> > > > >
> > > > >             HttpServletResponse response = (HttpServletResponse)
> > > > > facesContext.getExternalContext().getResponse();
> > > > >             response.sendRedirect (url);
> > > > >             facesContext.responseComplete();
> > > > >
> > > > > but it dosen't work the way I expect it to.. I presume this just
> > > > > redirects to another JSF page right ? ... so how do I convince it
> > > > to
> > > > > go to google.com < http://google.com> for example ???
> > > >
> > > >
> > >
> >
>

Re: redirect question

Posted by CD <dc...@gmail.com>.
On 3/29/07, Sorin Silaghi <so...@gmail.com> wrote:
>
> I am using it as a hack for JSCookMenu :D ....Sadly it didn't work this
> way ... the thing is the URL I'm sending it to is in the same application
> but it's a servlet, not a JSF page. I'll try in the morning again maybe i've
> missed something...
>
> 10x
>
> On 3/29/07, CD <dc...@gmail.com> wrote:
> >
> > Any particular reason you are performing a redirect (I'm assuming you
> > are using this as a command link) rather than just using a standard output
> > link?
> >
> > Regardless of the answer, I am in agreement with David.  One suggestion
> > I can make is to be sure you encode the redirect url with the
> > response.encodeRedirectURL() method.  To redirect to an external site
> > outside of the application context, you will need to supply an absolute URL.
> >
> >
> > HTH,
> > CD
> >
> >
> >  On 3/29/07, David Delbecq <delbd+jakarta@oma.be > wrote:
> > >
> > > This is the way to go. However it will throw an exception is response
> > > has already been committed.
> > > also the url must be either full ("http://......") either an url
> > > relative to current webapplication.
> > >
> > > Sorin Silaghi a écrit :
> > > > Hello,
> > > >
> > > >       This is a really easy one.. how can i redirect from the
> > > backing
> > > > bean to something that is not jsf... like to an external link for
> > > > example ???
> > > >
> > > > I've tried the whole
> > > >
> > > >             HttpServletResponse response = (HttpServletResponse)
> > > > facesContext.getExternalContext().getResponse();
> > > >             response.sendRedirect (url);
> > > >             facesContext.responseComplete();
> > > >
> > > > but it dosen't work the way I expect it to.. I presume this just
> > > > redirects to another JSF page right ? ... so how do I convince it to
> > >
> > > > go to google.com < http://google.com> for example ???
> > >
> > >
> >
>

Re: redirect question

Posted by Sorin Silaghi <so...@gmail.com>.
I am using it as a hack for JSCookMenu :D ....Sadly it didn't work this way
... the thing is the URL I'm sending it to is in the same application but
it's a servlet, not a JSF page. I'll try in the morning again maybe i've
missed something...

10x

On 3/29/07, CD <dc...@gmail.com> wrote:
>
> Any particular reason you are performing a redirect (I'm assuming you are
> using this as a command link) rather than just using a standard output link?
>
> Regardless of the answer, I am in agreement with David.  One suggestion I
> can make is to be sure you encode the redirect url with the
> response.encodeRedirectURL() method.  To redirect to an external site
> outside of the application context, you will need to supply an absolute URL.
>
>
> HTH,
> CD
>
>
> On 3/29/07, David Delbecq <de...@oma.be> wrote:
> >
> > This is the way to go. However it will throw an exception is response
> > has already been committed.
> > also the url must be either full ("http://......") either an url
> > relative to current webapplication.
> >
> > Sorin Silaghi a écrit :
> > > Hello,
> > >
> > >       This is a really easy one.. how can i redirect from the backing
> > > bean to something that is not jsf... like to an external link for
> > > example ???
> > >
> > > I've tried the whole
> > >
> > >             HttpServletResponse response = (HttpServletResponse)
> > > facesContext.getExternalContext().getResponse();
> > >             response.sendRedirect (url);
> > >             facesContext.responseComplete();
> > >
> > > but it dosen't work the way I expect it to.. I presume this just
> > > redirects to another JSF page right ? ... so how do I convince it to
> > > go to google.com <http://google.com> for example ???
> >
> >
>

Re: redirect question

Posted by CD <dc...@gmail.com>.
Any particular reason you are performing a redirect (I'm assuming you are
using this as a command link) rather than just using a standard output link?

Regardless of the answer, I am in agreement with David.  One suggestion I
can make is to be sure you encode the redirect url with the
response.encodeRedirectURL() method.  To redirect to an external site
outside of the application context, you will need to supply an absolute URL.

HTH,
CD


On 3/29/07, David Delbecq <de...@oma.be> wrote:
>
> This is the way to go. However it will throw an exception is response
> has already been committed.
> also the url must be either full ("http://......") either an url
> relative to current webapplication.
>
> Sorin Silaghi a écrit :
> > Hello,
> >
> >       This is a really easy one.. how can i redirect from the backing
> > bean to something that is not jsf... like to an external link for
> > example ???
> >
> > I've tried the whole
> >
> >             HttpServletResponse response = (HttpServletResponse)
> > facesContext.getExternalContext().getResponse();
> >             response.sendRedirect(url);
> >             facesContext.responseComplete();
> >
> > but it dosen't work the way I expect it to.. I presume this just
> > redirects to another JSF page right ? ... so how do I convince it to
> > go to google.com <http://google.com> for example ???
>
>

Re: redirect question

Posted by David Delbecq <de...@oma.be>.
This is the way to go. However it will throw an exception is response
has already been committed.
also the url must be either full ("http://......") either an url
relative to current webapplication.

Sorin Silaghi a écrit :
> Hello,
>
>       This is a really easy one.. how can i redirect from the backing
> bean to something that is not jsf... like to an external link for
> example ???
>
> I've tried the whole
>
>             HttpServletResponse response = (HttpServletResponse)
> facesContext.getExternalContext().getResponse();
>             response.sendRedirect(url);       
>             facesContext.responseComplete();
>
> but it dosen't work the way I expect it to.. I presume this just
> redirects to another JSF page right ? ... so how do I convince it to
> go to google.com <http://google.com> for example ???