开发者

Is there something like <c:url> for JSF?

开发者 https://www.devze.com 2023-04-12 02:28 出处:网络
Is there a taglib in JSF for inserting the proper application context root in any URL I want, just like th开发者_开发技巧e <c:url> tag in JSP does?Not exactly that, but all JSF components which

Is there a taglib in JSF for inserting the proper application context root in any URL I want, just like th开发者_开发技巧e <c:url> tag in JSP does?


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" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号