Skip to main content

Navigation to 'external' URL in JSF 2.0

2 replies [Last post]
Joined: 2003-06-26

Hi all,

I would like to implement a that targets a URL outside my web-application.

I've read about 'workarounds' that implement a PhaseListener.

However, as Seam supports a tag, I was wondering if JSF 2.0 might implement something similar now as well.

Or maybe I missed something trivial?

Thank you very much!!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-01-26

Implicit navigation doesn't work, the navigation is relative to the root as opposed
to being absolute. This is a major headache not least in relation to the desire of
many to move from https to http. Have a google on Jan Luehe's code which
downshifts from https to http, specifically the routine. What it looks
like to me is that you can access the ServletRequest via the @ManagedProperty
annotation (ServletRequest request) then do the stuff below and it should work.

I am way out of my comfort zone here, but if you play about with this I've an
a feeling it might work out ok.

public void doFilter(ServletRequest req, ServletResponse res,
HttpServletRequest httpReq = (HttpServletRequest) req;
String redirectUrl = "http://" + req.getServerName() + ":"
+ httpPort + httpReq.getRequestURI();
String queryString = httpReq.getQueryString();
if (queryString != null) {
redirectUrl += "?" + queryString;
((HttpServletResponse) res).sendRedirect(redirectUrl);

The navigation handler stuff probably doesn't figure in this context but should!

FacesContext fc = FacesContext.getCurrentInstance();
NavigationHandler nav = fc.getApplication().getNavigationHandler();
nav.handleNavigation(fc, null, "loginExpired?faces-redirect=true");

Note that you can do some useful things like this to clean your code up
(thanks for Ed Burns and his JSF 2.0 book):

public abstract class AbstractBackingBean {

@ManagedProperty(value = "#{facesContext}")
private FacesContext facesContext;
@ManagedProperty(value = "#{application}")
private ServletContext application;
@ManagedProperty(value = "#{requestScope}")
private Map requestMap;
@ManagedProperty(value = "#{sessionScope}")
private Map sessionMap;
@ManagedProperty(value = "#{view}")
private UIViewRoot viewRoot;
@ManagedProperty(value = "#{flash}")
private Flash flash;
@ManagedProperty(value = "#{session}")
private HttpSession session;
@ManagedProperty(value = "#{request}")
private ServletRequest request;

Hopefully someone with more expertise in this area can piece this together
and help to arrive at a solution.


Joined: 2003-06-12

How about simply using implicit navigation in the backing bean in question?