Re: return url from action method, OR other option....

2006-03-03 Thread Laurie Harper

Mario Ivankovits wrote:

Hi Dean!

but, unfortunately, I have to query another service for the URL to
really redirect to!!!  This means, I can't put the URL in the
faces-config.xml file.  Is there any way to do any of these options(or
otherslist is not exhaustive probably)

I am not definitely sure, but maybe a navigation handler could help.

*) create a class which extends from
"javax.faces.application.NavigationHandler"
*) create a constructor which takes one parameter which is also a
NavigationHandler - we call it originalHandler
*) override handleNavigation
*) configure this class in your faces-config.xml
*) if the fromAction is a url (e.g. starts with http://) get the
externalContext/response object - cast it to httpServletresponse and
*) call sendRedirect (or so, cant remember now)
*) else call originalHandler.handleNavigation


Note that you can achieve the same thing in your backing bean action, 
without having to install a view handler. The trick is to tell JSF 
you've handled the response so it skips generating one. Something like this:


  public String myAction() {
String url = getMyUrl();
FacesContext ctx = FacesContext.getCurrentInstance();
ctx.getExternalContext().redirect(url);
ctx.responseComplete();
return null;
  }

L.



Re: return url from action method, OR other option....

2006-03-03 Thread Dean D Hiller




sweet, thanks much..much better than the answer I got on sun's
forums :).
thanks,
dean

Mario Ivankovits wrote:

  Hi Dean!
  
  
but, unfortunately, I have to query another service for the URL to
really redirect to!!!  This means, I can't put the URL in the
faces-config.xml file.  Is there any way to do any of these options(or
otherslist is not exhaustive probably)

  
  I am not definitely sure, but maybe a navigation handler could help.

*) create a class which extends from
"javax.faces.application.NavigationHandler"
*) create a constructor which takes one parameter which is also a
NavigationHandler - we call it originalHandler
*) override handleNavigation
*) configure this class in your faces-config.xml
*) if the fromAction is a url (e.g. starts with http://) get the
externalContext/response object - cast it to httpServletresponse and
*) call sendRedirect (or so, cant remember now)
*) else call originalHandler.handleNavigation

  
  
1. return a URL from action methods like http://x.com

  
  this is required for the above
  
  
2. modify the faces-config dynamically like changing a mapping for
"success" and then returning "success" in the submit method.

  
  Not possible. myFaces wont reload it, the best you can archive here is
to reload the whole application - for sure not what you want ;-)
  
  
3. interact with ServletRequest and tell it to redirect(though I don't
want to depend on servlets and would like to be portable between
portlets and servlets maybeI know nothing about portlets so don't
know if portability is useful or not yet)

  
  This is what the above does. But for sure, not portlet compatible. But I
think the requirement itself isnt protlet compatible. What should a
protlet engine do if you direct the browser to do a redirect.
  
  
4. add a servlet filter somehow such that it can look at the url
returned from the submit method?

  
  not possible.

So, now dig into JSF an try it ;-)

Ciao,
Mario

  





Re: return url from action method, OR other option....

2006-03-03 Thread Mario Ivankovits
Hi Dean!
> but, unfortunately, I have to query another service for the URL to
> really redirect to!!!  This means, I can't put the URL in the
> faces-config.xml file.  Is there any way to do any of these options(or
> otherslist is not exhaustive probably)
I am not definitely sure, but maybe a navigation handler could help.

*) create a class which extends from
"javax.faces.application.NavigationHandler"
*) create a constructor which takes one parameter which is also a
NavigationHandler - we call it originalHandler
*) override handleNavigation
*) configure this class in your faces-config.xml
*) if the fromAction is a url (e.g. starts with http://) get the
externalContext/response object - cast it to httpServletresponse and
*) call sendRedirect (or so, cant remember now)
*) else call originalHandler.handleNavigation

> 1. return a URL from action methods like http://x.com
this is required for the above
> 2. modify the faces-config dynamically like changing a mapping for
> "success" and then returning "success" in the submit method.
Not possible. myFaces wont reload it, the best you can archive here is
to reload the whole application - for sure not what you want ;-)
> 3. interact with ServletRequest and tell it to redirect(though I don't
> want to depend on servlets and would like to be portable between
> portlets and servlets maybeI know nothing about portlets so don't
> know if portability is useful or not yet)
This is what the above does. But for sure, not portlet compatible. But I
think the requirement itself isnt protlet compatible. What should a
protlet engine do if you direct the browser to do a redirect.
> 4. add a servlet filter somehow such that it can look at the url
> returned from the submit method?
not possible.

So, now dig into JSF an try it ;-)

Ciao,
Mario