在JSF primefaces应用程序上重用一些.xhtml页面 [英] Reuse some .xhtml pages on a JSF primefaces application
问题描述
我使用JSF和PrimeFaces开发了一个简单的应用程序,这是我面临的一个问题:
I developing a simple application using JSF and PrimeFaces and here's a problem that I'm facing:
这些是具有Person
属性的托管bean:
These are managed beans that have a Person
property:
-
ClientBean
-
EmployeeBean
ClientBean
EmployeeBean
我有person.xhtml
可以显示某个人的数据.我在client.xhtml
和employee.xhtml
上包括了person.xhtml
.我需要创建两个person.xhtml
,因为我使用的是不同的bean.我想做的是这样的:
I have the person.xhtml
that shows the data from a person. I include the person.xhtml
on a client.xhtml
and employee.xhtml
. I need to create two person.xhtml
because I'm using different beans. What I want to do is something like that:
<c:set var="person" value="clientBean.person" />
<ui:include src="person.xhtml"/>
<c:set var="person" value="employeeBean.person" />
<ui:include src="person.xhtml"/>
在我的person.xhtml
中,我可以使用#{person.name}
,#{person.dateOfBirth}
.
我搜索并在JSF中使用<c:set/>
是错误的.
And in my person.xhtml
I can use #{person.name}
, #{person.dateOfBirth}
.
I searched and use <c:set/>
in JSF is wrong.
任何人都可以帮忙吗?
推荐答案
将其作为<ui:param>
传递.
<ui:include src="person.xhtml">
<ui:param name="person" value="#{clientBean.person}" />
</ui:include>
<ui:include src="person.xhtml">
<ui:param name="person" value="#{employeeBean.person}" />
</ui:include>
如有必要,将person.xhtml
注册为标记文件以使其看起来更好,另请参见
Register person.xhtml
if necessary as a tag file to make it look better, see also When to use <ui:include>, tag files, composite components and/or custom components?
<my:personForm value="#{clientBean.person}" />
<my:personForm value="#{employeeBean.person}" />
当心重复的组件ID错误.另请参见在重复使用时避免重复的ID同一命名容器中的小面组合物.
Beware of duplicate component ID errors. See also Avoiding duplicate ids when reusing facelets compositions in the same naming container.
这篇关于在JSF primefaces应用程序上重用一些.xhtml页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!