我是Java编程的初学者,正在做一个使用素数面的项目。我想在XHTML页面中包含另一个XHTML页面。include页面位于/WEB-INF/facelets/include.xhtml(它有一些来自托管Bean的数据(中
在我的";page.xhtml";,一开始,我把这行放在<ui:定义名称=";内容">:
<ui:include src="WEB-INF/facelets/include.xhtml" />
但是,它不起作用。
后来,我尝试在<ui:定义名称=";内容">
<ui:include src="WEB-INF/facelets/include.xhtml">
<ui:param name="fullName" value="#{identityInformationBean.fullName}" />
</ui:include>
并且在";include.xhtml":
<h:outputText
rendered="#{fullName!=null}"
value="#{fullName}" />
但是,它也不起作用。尽管如此,如果我这样做:
在";page.xhtml";
<ui:include src="WEB-INF/facelets/include.xhtml">
<ui:param name="fullName" value="Helen" />
</ui:include>
";include.xhtml";正确接收信息。
我试着将include文件注册为标记文件,正如这里所建议的那样。如何使用JSF 2.0 Facelets在XHTML中包含另一个XHTML?但是,它不起作用。
有解决这个问题的办法吗?谢谢
这是来自";include.xhtml":
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:outputText
rendered="#{identityInformationBean.fullName!=null}"
value="#{identityInformationBean.fullName}" />
</ui:composition>
这是来自";page.xhtml":
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" template="templates/generaltemplate.xhtml">
<ui:define name="content">
<h2>
<h:outputText value="Identity Information"/>
</h2>
</ui:define>
</ui:composition>
我不确定您为什么需要ui:param
。把include文件看作是省去了在所有可能使用它的页面中键入包含代码的麻烦。你不需要给它传递参数。
使用一行代码怎么样:<ui:include src="WEB-INF/facelets/include.xhtml"/>
并且include文件将具有<h:outputText value="#{identityInformationBean.fullName}"/>