是否有类似< c:url>对于JSF? [英] Is there something like <c:url> for JSF?
问题描述
JSF中是否有一个taglib用于在我想要的任何URL中插入正确的应用程序上下文根,就像JSP中的< c:url>
标记一样? / p>
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?
推荐答案
不完全是这样,但所有引用URL资源的JSF组件都已经自动包含正确的上下文路径,最终也是 FacesServlet
映射。例如 < h:link>
:
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" />
呈现类似的内容(假设您的上下文路径是 / contextname
和你的 FacesServlet
映射在 *。xhtml
):
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>
您可以通过 < f:param>
:
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>
它呈现如下内容:
<a href="/contextname/otherpage.xhtml?foo=bar">Link to other page</a>
其他链接组件也是 < h:outputStylesheet>
, < h:outputScript>
和 < h:graphicImage>
:
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" />
它呈现如下内容:
<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" />
这篇关于是否有类似< c:url>对于JSF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!