jsf - 在 XHTML 页面中包含另一个 XHTML 页面的问题
问题描述
我是一名 Java 编程初学者,我正在使用 primefaces 做一个项目。我想在 XHTML 页面中包含另一个 XHTML 页面。包含页面位于 /WEB-INF/facelets/include.xhtml (它有一些来自托管 Bean 的数据)
在我的“page.xhtml”中,首先,我将这一行放在 <ui:define name="content"> 中:
<ui:include src="WEB-INF/facelets/include.xhtml" />
但是,它不起作用。
后来,我尝试在 <ui:define name="content">
<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”正确接收信息。
我曾尝试将包含文件注册为标记文件,如此处建议的如何使用 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
. 将包含文件视为只是省去了将包含的代码输入到所有可能使用它的页面中的麻烦。您不需要向它传递参数。
使用单行代码怎么样:<ui:include src="WEB-INF/facelets/include.xhtml"/>
包含文件会有<h:outputText value="#{identityInformationBean.fullName}"/>
推荐阅读
- android - Android,获取用户在奥利奥及以上的工作资料邮箱
- ecmascript-6 - ES6 箭头函数 - 查找数组中出现频率最高的项
- javascript - 是否可以在 JavaScript 中更改闭包内的变量?
- php - 我的 php while 循环没有解析整个表
- javascript - d3.format 1 个十进制加字母 X
- reactjs - React Native undefined 不是一个对象(评估'HomeScreen.props.navigation')
- mysql - 如何通过终端在mysql中连续上传文件的整个文本
- android - 尝试为空活动运行 Android Studio 模拟器时出错
- python - 在完全执行完成之前结束scrapy runpider
- html - 禁用字体真棒图标上的颜色