JSF中是否有一个taglib,用于在我想要的任何URL中插入正确的应用程序上下文根,就像<c:url>JSP中的标记一样?
不完全是这样,但所有引用URL资源的JSF组件都已经自动包含正确的上下文路径,最终也包含FacesServlet映射.例如<h:link>:
<h:link value="Link to other page" outcome="otherpage" />
Run Code Online (Sandbox Code Playgroud)
它呈现类似的东西(假设您的上下文路径是/contextname并且您FacesServlet的映射*.xhtml):
<a href="/contextname/otherpage.xhtml">Link to other page</a>
Run Code Online (Sandbox Code Playgroud)
您可以包括请求参数<f:param>:
<h:link value="Link to other page" outcome="otherpage">
<f:param name="foo" value="#{bean.foo}" />
</h:link>
Run Code Online (Sandbox Code Playgroud)
它呈现如下:
<a href="/contextname/otherpage.xhtml?foo=bar">Link to other page</a>
Run Code Online (Sandbox Code Playgroud)
其他链接部件也做到这一点是<h:outputStylesheet>,<h:outputScript>和<h:graphicImage>,JS和图像分别为CSS:
<h:outputStylesheet library="default" name="css/foo.css" />
<h:outputScript library="default" name="js/foo.js" />
<h:graphicImage library="default" name="images/foo.png" />
Run Code Online (Sandbox Code Playgroud)
它呈现如下:
<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" />
Run Code Online (Sandbox Code Playgroud)