Skip to main content

Navigation to 'external' URL in JSF 2.0

2 replies [Last post]
jbulck
Offline
Joined: 2003-06-26
Points: 0

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.
(http://blogs.sun.com/jtb/entry/poor_man_s_jsf_navigation)

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!!
J.

Reply viewing options

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

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 MyFilter.java 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.

[code]
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);
[/code]

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

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

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):

[code]
@RequestScoped
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;
[/code]

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

Regards,
Brendan.

mpscholz
Offline
Joined: 2003-06-12
Points: 0

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