【发布时间】:2020-12-14 23:56:32
【问题描述】:
我是一名 Java 编程初学者,我正在使用 primefaces 做一个项目。我想在 XHTML 页面中包含另一个 XHTML 页面。包含页面位于 /WEB-INF/facelets/include.xhtml (它有一些来自托管 Bean 的数据)
在我的“page.xhtml”中,首先,我将这一行放在
<ui:include src="WEB-INF/facelets/include.xhtml" />
但是,它不起作用。
后来,我尝试在
<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”正确接收信息。
我曾尝试将包含文件注册为标记文件,正如此处How to include another XHTML in XHTML using JSF 2.0 Facelets? 所建议的那样 但是,它不起作用。
有解决这个问题的办法吗?谢谢!
这是来自“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>
【问题讨论】:
-
很难推断和理解“不起作用”的确切含义。看来您是在谈论在包含文件中显示特定的 bean 属性?换句话说,包含操作工作得非常好(即,当您将一些随机文本(例如“test”)添加到包含文件时,它会出现在您希望它出现的位置),但是变量并没有按照您的方式解析预计?请在描述问题时少含糊,更具体。 “它不起作用”是您能想到的最糟糕的问题描述。
-
@BalusC 感谢您的回答。好吧,我的包含文件 (include.xhtml) 包含一些 beans 属性,当我尝试在 page.xhtml 中包含“include.xhtml”时(按照我提到的方式),这个属性不会出现。
标签: jsf xhtml facelets managed-bean