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

亡梦爱人 提交于 2019-12-20 02:53:02

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/7730483/is-there-something-like-curl-for-jsf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!