尝试执行“包含"操作时出现问题在JSF中 [英] Problem trying to do an "include" in JSF
问题描述
我正在尝试在我的所有页面中包含一大堆静态html.我尝试了下面的代码,但是没有用.我还尝试了其他几种方法,但无法使其正常工作.我正在阅读有关以某种方式使用ui标签的信息,但是我也无法使其正常工作.要包含JSF页面,我需要做些什么.
I'm trying to include a chunk of static html in all of my pages. I tried the code below and it didn't work. I've also tried a few other ways and can't get it to work. I was reading about somehow using ui tags, but I couldn't get that to work either. What do I need to do to include a page with JSF.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:head>
...
</h:head>
<h:body>
<jsp:include src="/common/includes/founcred1.html" />
...
</h:body>
推荐答案
鉴于标记的XML语法,您似乎正在使用Facelets(*.xhtml
)作为视图技术. Facelets是一种完全不同的视图技术,是JSP的继承者.您不应该在Facelets中使用JSP标记.现在忘记JSP.使用Facelets标签.它们将由XML名称页xmlns:ui="http://java.sun.com/jsf/facelets"
声明.要将页面片段包含在Facelets中,请使用 <ui:include>
标签.
Given the XML syntax of your markup, you seem to be using Facelets (*.xhtml
) as view technology. Facelets is a completely distinct view technology and the successor of JSP. You should not be using JSP tags in Facelets. Forget JSP for now. Use Facelets tags. They are to be declared by the XML namespage xmlns:ui="http://java.sun.com/jsf/facelets"
. To include page fragments in Facelets, use <ui:include>
tag.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:head>
...
</h:head>
<h:body>
<ui:include src="/common/includes/founcred1.xhtml" />
</h:body>
</html>
您只需要将founcred1.html
重命名为founcred1.xhtml
并将内容包装在<ui:composition>
中.
You only need to rename your founcred1.html
to founcred1.xhtml
and wrap the content in an <ui:composition>
.
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
<p>HTML here</p>
</ui:composition>
另请参见:
- 何时使用< ui:include> ;、标记文件,复合组件和/或自定义组件?
- When to use <ui:include>, tag files, composite components and/or custom components?
See also:
这篇关于尝试执行“包含"操作时出现问题在JSF中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!