链接导航未检测 JSF 2.0 Facelets 页面中的模板
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
<title><ui:define name="title">Page 2</ui:define></title>
<ui:composition template="template/common/commonLayout.xhtml">
<ui:define name="content">
This is the content of Page 2 page<br/>
<h:form prependId="false">
<h:commandButton id="goToIndex" value="Go to Index" action="index" />
</h:form>
<a href="index.xhtml">Index</a>
</ui:define>
</ui:composition>
</h:body>
</html>
我有两个相同的facelets 页面:index.xhtml 和page2.xhtml,它们相互链接。我还有一个模板文件。除了标题中的页面名称、内容文本和 commandButton 值之外,index 和 page2 之间的代码没有任何区别。
当我单击表单实现的 goToIndex 按钮导航到index.xhtml 时,一切都按预期工作:它转到index.xhtml。但是,当我单击 [a href] 链接实现的链接导航到index.xhtml 时,它会转到index.xhtml,但似乎忽略页面的所有模板设置,包括任何表单标记。唯一呈现的是限制在“内容”定义中的文本,但没有任何 css 格式。
这件事是双向发生的。 “index -> page2”和“pag2 -> index”
知道为什么会发生这种情况吗?
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
<title><ui:define name="title">Page 2</ui:define></title>
<ui:composition template="template/common/commonLayout.xhtml">
<ui:define name="content">
This is the content of Page 2 page<br/>
<h:form prependId="false">
<h:commandButton id="goToIndex" value="Go to Index" action="index" />
</h:form>
<a href="index.xhtml">Index</a>
</ui:define>
</ui:composition>
</h:body>
</html>
I have two identical facelets pages: index.xhtml and page2.xhtml which link to each other. I also have a template file. There is no difference in the code between index and page2, apart from the name of the pages in the title, content text and commandButton values.
When I click on the goToIndex button implemented by the form to navigate to index.xhtml, everything works as expected: it goes to index.xhtml. However, when I click on the link implemented by the [a href] link to navigate to index.xhtml, it goes to index.xhtml but seems to ignore all the template settings for the page, including any form tag. The only thing rendered is the text confined in the "content" definition, but without any css formatting whatsoever.
This thing happens both way round. "index -> page2" and "pag2 -> index"
Any idea why this occurs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由
调用的页面未由 faces servlet 处理,因此未正确翻译且不包含 css/js。
查看您的 web.xml 并检查 faces servlet 的映射方式。在那里您可能会发现类似的内容:
您可以将模式更改为:
然后所有带有 xhtml 前缀的文件将由 faces servlet 处理。但是,如果在您的项目中 xhtml 前缀用于 Facelet 之外的其他目的,这可能会导致问题。
另一种方法是使用
h:link
而不是a:href
:其中结果属性采用不带 .xhtml 的目标页面。
The page that is called by
<a href ...>
isn't processed by the faces servlet and therefore not correctly translated and no css/js included.Look in your web.xml and check how the faces servlet is mapped. There you might find something like:
You could change the pattern to:
Then all files with the xhtml prefix will be processed by the faces servlet. However this could cause problems if in you project the xhtml prefix is used for other purposes than facelets.
Another way would be to use
h:link
instead ofa:href
:where the outcome attribute takes the target page without .xhtml.