使用 Facelets 模板进行导航不起作用
我在使用 Facelets 时遇到导航问题。
我的主模板位于 /WEB-INF
中:
<h:body>
<div id="container">
<div id="header">
<ui:insert name="header">Header</ui:insert>
</div>
<div id="navigation">
<a href="ram.xhtml">RAM</a>
<a href="mobo.xhtml">Motherboard</a>
<a href="video.xhtml">Video Card</a>
</div>
<div id="content">
<ui:insert name ="content"></ui:insert>
</div>
</div>
</h:body>
然后是 2 个看起来完全相同的模板客户端,index.xhtml
和 ram.xhtml
:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="./WEB-INF/layoutTemplate.xhtml">
<ui:define name="header">
some text
</ui:define>
<ui:define name="content">
some content
</ui:define>
</ui:composition>
如果这些页面中的任何一个在 web.xml
中设置为欢迎页面,它们就会使用 CSS 和所有内容正确呈现。但是,如果我尝试使用链接从一个页面导航到另一页面,我会得到
此 XML 文件似乎没有任何与其关联的样式信息。文档树如下所示。
任何提示将不胜感激。
I'm having some trouble with navigation when using Facelets.
I have my master template in /WEB-INF
:
<h:body>
<div id="container">
<div id="header">
<ui:insert name="header">Header</ui:insert>
</div>
<div id="navigation">
<a href="ram.xhtml">RAM</a>
<a href="mobo.xhtml">Motherboard</a>
<a href="video.xhtml">Video Card</a>
</div>
<div id="content">
<ui:insert name ="content"></ui:insert>
</div>
</div>
</h:body>
and then 2 template clients that look exactly the same, index.xhtml
and ram.xhtml
:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="./WEB-INF/layoutTemplate.xhtml">
<ui:define name="header">
some text
</ui:define>
<ui:define name="content">
some content
</ui:define>
</ui:composition>
If either of these pages are set as the welcome page in the web.xml
, they are rendered correctly, with CSS and everything. But if I try to navigate from one page to the other using the link I get
This XML file does not appear to have any style information associated with it. The document tree is shown below.
Any hints would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这意味着请求 URL(如浏览器地址栏中显示的)与
web.xml
中定义的FacesServlet
的 URL 模式不匹配。这些链接
需要将
FacesServlet
映射到*.xhtml
。但是,如果它映射到例如*.jsf
并将其更改为*.xhtml
由于某种原因而不是一个选项(但是我强烈推荐它),那么您会需要修复链接或者,更好的是,只需使用
。它将隐式附加正确的上下文路径和FacesServlet
映射:另请参阅:
This means that the request URL (as appears in browser address bar) didn't match the URL pattern of the
FacesServlet
as definied inweb.xml
.Those links
expects the
FacesServlet
to be mapped on*.xhtml
. But if it's mapped on for example*.jsf
and changing it to*.xhtml
is not an option for some reason (I however strongly recommend it), then you'd need to fix the linksOr, better, just use
<h:link>
. It'll implicitly append the proper context path andFacesServlet
mapping:See also: