使用 Facelets 模板的导航不起作用 [英] Navigation with Facelets template not working
问题描述
我在使用 Facelets 时遇到了一些导航问题.
I'm having some trouble with navigation when using Facelets.
我在 /WEB-INF
中有我的主模板:
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>
然后是 2 个看起来完全相同的模板客户端,index.xhtml
和 ram.xhtml
:
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>
如果在 web.xml
中将这些页面中的任何一个设置为欢迎页面,则它们会正确呈现,并使用 CSS 和所有内容.但是,如果我尝试使用我得到的链接从一个页面导航到另一个页面
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
此 XML 文件似乎没有任何关联的样式信息.文档树如下所示.
This XML file does not appear to have any style information associated with it. The document tree is shown below.
任何提示将不胜感激.
推荐答案
这意味着请求 URL(显示在浏览器地址栏中)与定义的 FacesServlet
的 URL 模式不匹配在 web.xml
中.
This means that the request URL (as appears in browser address bar) didn't match the URL pattern of the FacesServlet
as definied in web.xml
.
那些链接
<a href="ram.xhtml">RAM</a>
<a href="mobo.xhtml">Motherboard</a>
<a href="video.xhtml">Video Card</a>
期望 FacesServlet
映射到 *.xhtml
.但是,如果它被映射到例如 *.jsf
并且出于某种原因将其更改为 *.xhtml
不是一个选项(但我强烈推荐它),那么你会需要修复链接
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 links
<a href="ram.jsf">RAM</a>
<a href="mobo.jsf">Motherboard</a>
<a href="video.jsf">Video Card</a>
或者,更好的是,只需使用 <h:link>
.它将隐式附加正确的上下文路径和 FacesServlet
映射:
Or, better, just use <h:link>
. It'll implicitly append the proper context path and FacesServlet
mapping:
<h:link value="RAM" outcome="ram" />
<h:link value="Motherboard" outcome="mobo" />
<h:link value="Video Card" outcome="video" />
另见:
- JSF 2.0 中的通信 - 隐式导航
这篇关于使用 Facelets 模板的导航不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!