Is there a taglib in JSF for inserting the proper application context root in any URL I want, just like the <c:url>
tag in JSP does?
Asked
Active
Viewed 2,603 times
2

BalusC
- 1,082,665
- 372
- 3,610
- 3,555

Cristiano Fontes
- 4,920
- 6
- 43
- 76
1 Answers
7
Not exactly that, but all JSF components which refer to an URL resource will already automatically include the proper context path and eventually also the FacesServlet
mapping. For example the <h:link>
:
<h:link value="Link to other page" outcome="otherpage" />
which renders something like (assuming that your context path is /contextname
and your FacesServlet
is mapped on *.xhtml
):
<a href="/contextname/otherpage.xhtml">Link to other page</a>
You can include request parameters by <f:param>
:
<h:link value="Link to other page" outcome="otherpage">
<f:param name="foo" value="#{bean.foo}" />
</h:link>
which renders something like:
<a href="/contextname/otherpage.xhtml?foo=bar">Link to other page</a>
Other link components which also do that are the <h:outputStylesheet>
, <h:outputScript>
and <h:graphicImage>
for CSS, JS and images respectively:
<h:outputStylesheet library="default" name="css/foo.css" />
<h:outputScript library="default" name="js/foo.js" />
<h:graphicImage library="default" name="images/foo.png" />
which renders something like:
<link rel="stylesheet" type="text/css" href="/contextname/javax.faces.resource/css/foo.css.xhtml?ln=default" />
<script type="text/javascript" src="/contextname/javax.faces.resource/js/foo.js.xhtml?ln=default"></script>
<img src="/contextname/javax.faces.resource/images/foo.png.xhtml?ln=default" />

BalusC
- 1,082,665
- 372
- 3,610
- 3,555