O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Linking Non-JSF Resources

You’ve already seen an example of a link to a different resource than the JSF view that rendered the screen containing the view, namely the link to the first preferences view in the menu area view. The logout link is another example, and in links to a regular JSP page instead of a JSF view:

[<h:outputLink value="../../logout.jsp">
  <h:outputText value="Logout" />
</h:outputLink>]

The logout.jsp page is located in the top directory for the application, so that accessing this page doesn’t trigger the authentication constraint declared for all resources in the expense directory; it wouldn’t make sense to have to login if the session has timed out just to be able to logout. I therefore specify the path as a relative path to the file located two directories up from the file with the link. An alternative is to use a JSF EL expression that adds the context path for the application to a context-relative path so that it makes sense to the browser:

[<h:outputLink 
  value="#{facesContext.externalContext.request.contextPath}/logout.jsp">
  <h:outputText value="Logout" />
</h:outputLink>]

The JSF EL expression evaluates to the application context path, e.g., /jsfbook if you use the default for the sample application, so the HTML link’s href attribute is rendered with the value /jsfbook/logout.jsp. It would, of course, be better if the link renderer added the context-path automatically for a context-relative path, but it slipped through the cracks for the JSF 1.0 specification. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required