java - 有没有类似<c :url> for JSF?

标签 java jsf jsf-2

JSF 中是否有用于在我想要的任何 URL 中插入正确的应用程序上下文根的标签库,就像 <c:url> JSP 中的标记呢?

最佳答案

不完全是这样,但是所有引用 URL 资源的 JSF 组件都已经自动包含了正确的上下文路径,并最终包含了 FacesServlet。映射。例如 <h:link> :

<h:link value="Link to other page" outcome="otherpage" />

呈现类似的内容(假设您的上下文路径是 /contextname 并且您的 FacesServlet 映射到 *.xhtml ):

<a href="/contextname/otherpage.xhtml">Link to other page</a>

您可以通过 <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> 分别针对 CSS、JS 和图像:

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

关于java - 有没有类似<c :url> for JSF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7730483/

相关文章:

java - 如何使用spring数据计算mongo文档嵌套数组中的项目?

java - 在不丢失编译时检查的情况下在 Eclipse 中构建多 SDK Android 应用程序

Java 将字符串添加到字符串数组

java - 无法使用复选框选择填充字符串

java - 如何删除 JSF 中 <?xml ...?> 的第一行?

validation - 注释约束后如何应用 JSF 验证器?

jsf - Apache Tomcat 和 TOMEE

java - :outputLabel not showing anything

java - Webfilter 只能在第二个响应中登录用户(记住我)

jsf - 显示 p :dialog using oncomplete only if custom validation in action was passed